Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

For Russell on OnMeasureItem answer

Posted on 2003-12-02
3
Medium Priority
?
571 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 400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

927 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