1. Home
  2. Computing & Technology
  3. Delphi Programming

How to Right Align a Menu Item

By Zarko Gajic, About.com

In most applications all (top level) menu items are aligned at the left side of the menu bar. I'm sure you have seen applications with at least one item aligned on the right side. In most cases this was the "Help" menu item.

Here's how to align a form's Help menu item (for example) on the right side of the menu bar, in Delphi applications.

  1. Add a TMainMenu component to a form (Form1)
  2. Add several (top level) menu items (with sub items)
  3. Have a menu item named "HelpMenuItem"
  4. Use the code below in the form's OnCreate event.
  5. Run the project ... note that the "Help" item is aligned on the right side of the menu bar.
procedure TForm1.FormCreate(Sender: TObject) ;
var
   mii: TMenuItemInfo;
   MainMenu: hMenu;
   Buffer: array[0..79] of Char;
begin
   MainMenu := Self.Menu.Handle;

   //GET Help Menu Item Info
   mii.cbSize := SizeOf(mii) ;
   mii.fMask := MIIM_TYPE;
   mii.dwTypeData := Buffer;
   mii.cch := SizeOf(Buffer) ;
   GetMenuItemInfo(MainMenu, HelpMenuItem.Command, false, mii) ;

   //SET Help Menu Item Info
   mii.fType := mii.fType or MFT_RIGHTJUSTIFY;
   SetMenuItemInfo(MainMenu, HelpMenuItem.Command, false, mii) ;
end;

Delphi tips navigator:
» How to Change the Colors of the TProgressBar
« ing Custom Code Templates in Delphi 2006

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2006 Tips
  7. How to Right Align a Menu Item in a Delphi application

©2009 About.com, a part of The New York Times Company.

All rights reserved.