Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TMainMenu Font Size

Status
Not open for further replies.

Opieo

Programmer
Jul 26, 2006
454
GB
I have searched high and low and cannot find where to make the TMainMenu Items have a larger font size for my program.

Can anyone advise how this can be accomplished?

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
There is no property you can set to do this, so you'll have to handle the drawing of the items yourself. To do this set the OwnerDraw property of the TMainMenu to true. Then create OnDrawItem and OnMeasureItem event handlers, and assign these to the events for each menu item that you want to change (any menu item that does not use these event handlers will be drawn in the normal way).
This example shows how to change the font size to 15

Code:
procedure TForm1.MenuDrawItem(Sender: TObject; ACanvas: TCanvas;
  ARect: TRect; Selected: Boolean);
var
  MyCaption: string;
begin
  MyCaption := (Sender as TMenuItem).Caption;
  ACanvas.Font.Size := 15;
  ARect.Left := 5;
  DrawText(ACanvas.Handle, PChar(MyCaption), -1, ARect, DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_NOCLIP);
end;

procedure TForm1.MenuMeasureItem(Sender: TObject; ACanvas: TCanvas;
  var Width, Height: Integer);
var
  NewSize: TSize;
begin
  ACanvas.Font.Size := 15;
  NewSize := ACanvas.TextExtent((Sender as TMenuItem).Caption);
  Width := NewSize.cx;
  Height := NewSize.cy;
end;

Steve
 
Thank you both.
Don, that code works perfectly.
I had to mod it a little for the other menu items such as
Main
Item 1
Sub 1
Sub 2
Sub 3
Item 2
Sub 4
Sub 5
My case was it was drawing Item 2 over top of Item 1.
I made another small function for it that just it used, and Item 1 and all the Subs used the original you posted.
It works just fine, and I tried getting it to automatically draw for dynamic purposes, but created some really funny looking menus in the process and no success at end.
For now it is fine. And thank you quite much.

aaron,
I was looking at a bunch of the other posts about Menus and you seem to really like that ToolBar2K =)
I am giving it a look see to see all of its abilities and what it can do and such. Thank you for pointing me to that as well.

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top