Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

For Russell on OnMeasureItem answer

Posted on 2003-12-02
3
Medium Priority
?
567 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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