Solved

Color on the MainMenu

Posted on 2001-07-12
11
2,449 Views
Last Modified: 2012-05-05
Who can I change the color of the TMainMenu, without using Windows, but define some own colors?
0
Comment
Question by:easysoft_studios
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 1

Expert Comment

by:alx512
Comment Utility
I think you need to change the Menus.pas and include it to your project.
0
 
LVL 9

Expert Comment

by:ITugay
Comment Utility
Hi easysoft_studio,

not sure what you mean "without using Windows", but change color of TMainMenu not difficult in code.

type
  TForm1 = class(TForm)
    .....
    procedure FormCreate(Sender: TObject);
  public
    procedure DrawMenuItem(Sender: TObject; ACanvas: TCanvas;
      ARect: TRect; Selected: Boolean);
  end;

...

procedure TForm1.DrawMenuItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
var
  S: String;
begin
  with ACanvas do
  begin
    S := TMenuItem(Sender).Caption;
    if Selected then
      Brush.Color := clHighLight
    else
      Brush.Color := clLime;
    FillRect(ARect);
    DrawText(ACanvas.Handle, PChar(S), Length(S), ARect, DT_SINGLELINE or DT_VCENTER);
  end;

end;

procedure AllOnDrawTo(M: TMenuItem; P: TMenuDrawItemEvent);
var
  I: Integer;
begin
  M.OnDrawItem := P;
  for I := 0 to M.Count-1 do
    AllOnDrawTo(M.Items[I], P);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to MM.Items.Count -1 do
    AllOnDrawTo(MM.Items[I], DrawMenuItem);
end;

-----------
Igor.
0
 

Author Comment

by:easysoft_studios
Comment Utility
ITugay >> what I mean with the Windows colors, is the schemes, the user can set, so buttons, menuitems, fonts have the color/font the user want to. This have nothing to do with Delphi!


Sorry, but the code, only colors the itemes, not the whole MainMenu. That's what i'm looking for.


alx512 >> how should that help?
0
 
LVL 9

Expert Comment

by:ITugay
Comment Utility
Do you mean that rest of the top of the form should be colored too?

just add this line to DrawMenuItem procedure. MenuIndex = nnn - number of top menuitems-1. Let say if you have "File Edit View" then nn = 2.

    // this line fill rest of the top of the form
    if (Parent = nil) and (TMenuItem(Sender).MenuIndex = 1) and not Selected then
      ARect.Right := Width;

    FillRect(ARect);
    DrawText(ACanvas.Handle, PChar(S), Length(S), ARect, DT_SINGLELINE or DT_VCENTER);
  end;

end;
0
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
Comment Utility
hi,
component to make your menu look and feel like windows xp menus:
http://www.shagrouni.com/english/software/xpmenu.html

this is a example similar to what Igor gave:
http://www.delphi.about.com/library/weekly/aa100300a.htm
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Expert Comment

by:alx512
Comment Utility
Do you have a Delpthi source?
Copy menus.pas from source directory to your project dir.
Add it to the project. Then open it and do some modification like this:

if not Selected then
  begin
    OffsetRect(Rect, 1, 1);
    Font.Color := clBtnHighlight; // change to your color
    DrawText(Handle, PChar(Text), Length(Text), Rect, Flags);
    OffsetRect(Rect, -1, -1);
  end;
  if Selected and (ColorToRGB(clHighlight) = ColorToRGB(clBtnShadow)) then
  Font.Color := clBtnHighlight else // change to your color
  Font.Color := clBtnShadow; // change to your color
end;
DrawText(Handle, PChar(Text), Length(Text), Rect, Flags);
0
 
LVL 1

Expert Comment

by:h_mohsenian
Comment Utility
I have a TCoolMenu Object. it has so exciting properties.like : font,color,backgroun picture,... for Delphi 3.
please give me your email. I will send it to you.becouse its source has  2852 lines and it needs another obeject too. therefor i thinks that is better i send it.

best regards
hamed
0
 

Author Comment

by:easysoft_studios
Comment Utility
h_mohsenian >> my e-mail: easysoft_studios@hotmail.com
0
 
LVL 1

Expert Comment

by:h_mohsenian
Comment Utility
I sent it to u.i hope it can be usefull for u.

best regards
hamed
0
 

Author Comment

by:easysoft_studios
Comment Utility
I give the points to inthe for the xpmenu link. It *ucking cool!!
0
 

Author Comment

by:easysoft_studios
Comment Utility
very nice component! It's *ucking cool!!!

Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now