Get width of menu item

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm trying to right-align a context menu with its source control.

Here's what I have to LEFT align it:
'\\\
Dim pt As New Point(0, myButton.Height)
myContextMenu.Show(myButton, pt)
'///

It looks like I need the width of the context menu to get the correct point:
Dim pt as New Point(myButton.Width - myContextMenu.Width, myButton.Height)

But there is no "Width" property for the context menu or its items. Does
anyone know how to do this without owner drawing the context menu?

Thank you
 
Anon,

Try getting the rectangle associated with the control and use its Left and
Bottom properties.

For example:

private void MyControl_MouseUp( object sender, MouseEventArgs e )
{
if ( e.Button == MouseButtons.Right )
{
Point pt = new Point( this.ClientRectangle.Left,
this.ClientRectangle.Bottom );
this.contextMenu.MenuItems.Add( this.helpItem );
this.contextMenu.MenuItems.Add( this.scpiItem );
this.contextMenu.Show( this, pt );
this.contextMenu.MenuItems.Clear();
}
}

Hope that helps,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top