By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,699 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,699 IT Pros & Developers. It's quick & easy.

Get width of menu item

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"anon" wrote:
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

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.