G
gencheng
Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个快捷菜单项组件(TMenuItem),它可以改变菜单项的字体颜色。不过有这样的问题:当菜单项的Caption为减号'-',即让菜单起到分割条作用时,该菜单项显示的不是分割条,是什么都没显示,如何将分割条显示出来?当然还要保留改变菜单项字体颜色功能。
代码如下:
nit MenuItemBlue;
Interface
Uses Windows, SysUtils, Classes, Contnrs, Messages, Graphics, ImgList, ActnList, Menus;
Type
TMenuItemBlue = Class(TMenuItem)
Private
Protected
Procedure DoDrawItem(Sender: TObject; ACanvas: TCanvas;ARect: TRect; Selected: Boolean);
Public
Constructor Create(AOwner: TComponent); Override;
End;
Implementation
Uses Controls, Forms, Consts, Themes;
{ TMenuItemBlue }
Constructor TMenuItemBlue.Create(AOwner: TComponent);
Begin
Inherited;
self.OnDrawItem := DoDrawItem;
End;
Procedure TMenuItemBlue.DoDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
Begin
If Not (Trim(Caption)='-') Then
Begin
ACanvas.Font.Color := clHotLight; //字体亮蓝
ACanvas.TextOut(ARect.Left, ARect.Top, Caption); //字体颜色
End;
End;
End.
代码如下:
nit MenuItemBlue;
Interface
Uses Windows, SysUtils, Classes, Contnrs, Messages, Graphics, ImgList, ActnList, Menus;
Type
TMenuItemBlue = Class(TMenuItem)
Private
Protected
Procedure DoDrawItem(Sender: TObject; ACanvas: TCanvas;ARect: TRect; Selected: Boolean);
Public
Constructor Create(AOwner: TComponent); Override;
End;
Implementation
Uses Controls, Forms, Consts, Themes;
{ TMenuItemBlue }
Constructor TMenuItemBlue.Create(AOwner: TComponent);
Begin
Inherited;
self.OnDrawItem := DoDrawItem;
End;
Procedure TMenuItemBlue.DoDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
Begin
If Not (Trim(Caption)='-') Then
Begin
ACanvas.Font.Color := clHotLight; //字体亮蓝
ACanvas.TextOut(ARect.Left, ARect.Top, Caption); //字体颜色
End;
End;
End.