Solved

For Russell on OnMeasureItem answer

Posted on 2003-12-02
3
553 Views
Last Modified: 2012-08-13
----------------------------------------------------------
1. Make sure the menu/popupmenu has OwnerDraw set to true.
2. You have to handle the OnMeasureItem for the menu items, and change the Width Setting there.  The easiest way to do this is to create one method and assign all the menu items OnMeasureItem to it.
---------------------------------------------------------
Russell,

I can't find the OnMeasureItem for PopupMenu, it is under PopupMenu.Items.

Can you show me smoe sample code? Thanks.

Jammy
0
Comment
Question by:jlislo
3 Comments
 
LVL 8

Expert Comment

by:gmayo
Comment Utility
MyMenuItem1.OnMeasureItem := MyMeasureItem;
MyMenuItem2.OnMeasureItem := MyMeasureItem;
MyMenuItem3.OnMeasureItem := MyMeasureItem;
etc.

Or you can do it visually by creating an event handler for the first handler, then clicking on the event handler for the rest of the menu items and selecting the one created first. The Sender parameter will then contain the menuitem that it is measuring.

Geoff M.
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 100 total points
Comment Utility

The OnMeasureItem is not an event of the popupmenu/menu, but rather of the menu items (TMenuItem).

Simple example that binds all the popup menu items OnMeasureItem to a forms method

type
  TForm1            =  class(TForm)
     PopupMenu1:    TPopupMenu;
     miOne:         TMenuItem;
     miTwo:         TMenuItem;
     miThree:       TMenuItem;
     procedure      FormCreate(Sender: TObject);
     // Added to handle the OnMeasureItem for the menu items
     procedure      OnMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
     // Added so you can bind the popupup menu items to the forms OnMeasureItem handler
     procedure      BindPopupMenu(PopupMenu: TPopupMenu);
  private
     // Private declarations
  public
     // Public declarations
  end;

var
  Form1:            TForm1;

implementation
{$R *.DFM}

procedure TForm1.BindPopupMenu(PopupMenu: TPopupMenu);
var  dwIndex:    Integer;
begin

  // Make sure OwnerDraw is set
  PopupMenu.OwnerDraw:=True;

  // Iterate the items
  for dwIndex:=0 to Pred(PopupMenu.Items.Count) do
     // Set the OnMeasureItem event handler
     PopupMenu.Items[dwIndex].OnMeasureItem:=OnMeasureItem;

end;

procedure TForm1.OnMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
begin

  // Adjust the width only (set to your desired width)
  Width:=30;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin

  // Bind PopupMenu1 to the form handler for OnMeasureItem
  BindPopupMenu(PopupMenu1);

end;


Hope this helps,
Russell
0
 

Author Comment

by:jlislo
Comment Utility
Thanks again Russell
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Display a PDF file and get words from it 6 96
select query - oracle 16 81
LAN or WAN ? 11 58
Base1 Encode/Decode 3 0
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

10 Experts available now in Live!

Get 1:1 Help Now