Solved

For Russell on OnMeasureItem answer

Posted on 2003-12-02
3
563 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
ID: 9862213
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
ID: 9863112

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
ID: 9866330
Thanks again Russell
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

774 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