我试图通过创建从该组件派生的自己的组件来扩展TActionMainMenuBar。
我想做的一件事是允许沿菜单栏绘制渐变。我成功地做到了这一点,但是当指定的TActionManager设置为XPStyle时,菜单项出现了问题。
查看这些具有不同TActionManager样式集的图像:
平台默认设置(鼠标关闭并按下):


当TActionManager设置为Platform默认值时,背景将正确显示,您可以很好地看到渐变显示。
但是,当TActionManager设置为XPStyle时,某些项的渐变绘制不正确,只需查看第一项:
XP样式(鼠标翻转并按下):


你看不出什么好眼神。
我编辑了油漆中的图像,以大致了解我希望它是什么样子:
鼠标完毕并选择


我认为这将允许创建一些有趣的菜单样式。
下面是我到目前为止掌握的代码:
unit uMyMenu;
interface
uses
Classes,
Types,
Graphics,
GraphUtil,
ActnMan,
ActnCtrls,
ActnMenus,
PlatformDefaultStyleActnCtrls,
XPActnCtrls,
XPStyleActnCtrls;
type
TMyActionMenu = class(TActionMainMenuBar)
private
FColorStart: TColor;
FColorEnd: TColor;
procedure SetColorStart(AValue: TColor);
procedure SetColorEnd(AValue: TColor);
protected
procedure Paint(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ColorStart: TColor read FColorStart write SetColorStart default clSkyBlue;
property ColorEnd: TColor read FColorEnd write SetColorEnd default clHighlight;
end;
procedure Register;
implementation
{ TMyActionMenu }
constructor TMyActionMenu.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SetColorStart(clSkyBlue);
SetColorEnd(clHighlight);
ParentBackground := True;
ParentColor := False;
OnPaint := Paint;
end;
destructor TMyActionMenu.Destroy;
begin
inherited;
end;
procedure TMyActionMenu.SetColorStart(AValue: TColor);
begin
if FColorStart <> AValue then
begin
FColorStart := AValue;
Invalidate;
end;
end;
procedure TMyActionMenu.SetColorEnd(AValue: TColor);
begin
if FColorEnd <> AValue then
begin
FColorEnd := AValue;
Invalidate;
end;
end;
procedure TMyActionMenu.Paint(Sender: TObject);
var
Rect: TRect;
begin
Rect := GetClientRect;
GradientFillCanvas(TMyActionMenu(Sender).Canvas, FColorStart,
FColorEnd, Rect, gdVertical);
end;
procedure Register;
begin
RegisterComponents('Standard', [TMyActionMenu]);
end;
end.我不知道从哪里开始,或者改变什么,所以我期待着看到你的评论和回答。
更新
例如,将TActionMainMenuBar放置在渐变面板中,将ParentBackground设置为True类型的工作更合适。因此,我应该考虑使用SetSubComponent并将我的TMyActionMenu放入类似的面板容器中,然后以这种方式将梯度绘制到面板上。
不过,我会把这个问题留待进一步评论和建议。
发布于 2012-08-19 10:38:52
还有一个俄罗斯组件,它也可以进行渐变绘画。我没有测试它,我甚至不知道它是否满足了您的需求,但是也许您从查看它们的源代码中得到了一些想法。下面是链接(我使用谷歌翻译将网站翻译成英文):http://translate.google.com/translate?langpair=ru|en&u=http%3A%2F%2Fwww.roschinspb.narod.ru%2Fdevelop.html
https://stackoverflow.com/questions/12017787
复制相似问题