Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to change the color of a menu Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Oct-02
Category
VCL-Menu
Language
Delphi 2.x
Views
113
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to change the color of a menu

Answer:

You can set the menu to owner-drawn and draw the items yourself in the OnDrawItem 
handlers. This does not work for the menubar, however.

The menu colors are a system setting which the user can specify in the display 
properties applet. You should not mess with that. One can do so when the app is 
activated and restore the old setting when it is deactivated or closed, but that is 
also not very satisfactory since the change still hits all other running apps as 
well and in the case of changes to the color scheme it also may take a noticable 
delay to take effect.

If you want to play with it: drop a TApplicationEvents component on the form, 
connect the OnActivate and OnDeactivate events of it to handlers, add one for the 
forms OnClose event, modify as below.

1   { ... }
2   private
3   { Private declarations }
4   FOldMenuColor: TColorRef;
5   FOldMenuTextColor: TColorRef;
6   public
7   { Public declarations }
8   end;
9   
10  var
11    Form1: TForm1;
12  
13  implementation
14  
15  {$R *.DFM}
16  
17  procedure TForm1.ApplicationEvents1Activate(Sender: TObject);
18  var
19    newcolors: array[0..1] of TColorRef;
20    indices: array[0..1] of Integer;
21  begin
22    FOldMenuColor := ColorToRGB(clMenu);
23    FOldMenuTextColor := ColorToRGB(clMenuText);
24    newcolors[0] := ColorToRGB(clAqua);
25    newcolors[1] := ColorToRGB(clNavy);
26    indices[0] := COLOR_MENU;
27    indices[1] := COLOR_MENUTEXT;
28    SetSysColors(2, indices, newcolors);
29  end;
30  
31  procedure TForm1.ApplicationEvents1Deactivate(Sender: TObject);
32  var
33    newcolors: array[0..1] of TColorRef;
34    indices: array[0..1] of Integer;
35  begin
36    newcolors[0] := FOldMenuColor;
37    newcolors[1] := FOldMenuTextColor;
38    indices[0] := COLOR_MENU;
39    indices[1] := COLOR_MENUTEXT;
40    SetSysColors(2, indices, newcolors);
41  end;
42  
43  procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
44  begin
45    ApplicationEvents1Deactivate(self);
46  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC