Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to change menu color

911 views
Skip to first unread message

richard tsang

unread,
Jun 27, 2001, 3:18:47 AM6/27/01
to
Dear all,

I want to change the menu backgroup and highlighted color in Delphi,how can
I do that?

thanks.


M.H. Avegaart

unread,
Jun 27, 2001, 3:33:55 AM6/27/01
to
Delphi uses the standard Windows colors. If you want to change these you'll
have to set OwnerDraw to True and use the following OnAdvancedDrawItem event
for all menu items:

type
TMyMenuItem = class(TMenuItem);

procedure TForm1.MenuItemAdvancedDrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; State: TOwnerDrawState);
var
TopLevel: Boolean;
Win98Plus: Boolean;
OldAdvancedDrawItem: TAdvancedMenuDrawItemEvent;
begin
with ACanvas do
begin
Win98Plus := (Win32MajorVersion > 4) or
((Win32MajorVersion = 4) and (Win32MinorVersion > 0));
TopLevel := TMenuItem(Sender).GetParentComponent is TMainMenu;
if (odSelected in State) and (not TopLevel or (TopLevel and not
Win98Plus)) then
begin
Brush.Color := clRed;
Font.Color := clWhite;
end
else if Win98Plus and (odInactive in State) then
begin
Brush.Color := clGreen;
Font.Color := clSilver;
end
else
begin
Brush.Color := clGreen;
Font.Color := clWhite;
end;
OldAdvancedDrawItem := TMenuItem(Sender).OnAdvancedDrawItem;
try
TMenuItem(Sender).OnAdvancedDrawItem := nil;
TMyMenuItem(Sender).AdvancedDrawItem(ACanvas, ARect, State, TopLevel);
finally
TMenuItem(Sender).OnAdvancedDrawItem := OldAdvancedDrawItem;
end;
end;
end;


"richard tsang" <zc...@21cn.com> schreef in bericht news:3b398735_2@dnews...

0 new messages