You'll have to use the old TrackPopupMenu or TrackPopupMenuEx API calls for
that. You can use menu.show(...) to show a menu at a specific position, but
as you have found, you cannot align the menu or get the size of the menu
before calling it.
VB.Net Declarations
\\\
<DllImport("user32.dll", _
CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Function TrackPopupMenu( _
ByVal hMenu As IntPtr, _
ByVal uFlags As Int32, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal nReserved As Integer, _
ByVal hWnd As IntPtr, _
ByVal prcRect As IntPtr) As Integer
End Function
<DllImport("user32.dll", _
CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Function TrackPopupMenuEx( _
ByVal hmenu As IntPtr, _
ByVal uFlags As Integer, _
ByVal x As Short, _
ByVal y As Short, _
ByVal hwnd As IntPtr, _
ByVal lptpm As IntPtr) As Boolean
End Function
'uFlags
Private Const TPM_CENTERALIGN As Integer = &H4
Private Const TPM_LEFTALIGN As Integer = &H0&
Private Const TPM_RIGHTALIGN As Integer = &H8
Private Const TPM_BOTTOMALIGN As Integer = &H20
Private Const TPM_TOPALIGN As Integer = &H0&
Private Const TPM_VCENTERALIGN As Integer = &H10
Private Const TPM_NONOTIFY As Integer = &H80
Private Const TPM_RETURNCMD As Integer = &H100
Private Const TPM_LEFTBUTTON As Integer = &H0
Private Const TPM_RIGHTBUTTON As Integer = &H2
Private Const TPM_HORNEGANIMATION As Integer = &H800
Private Const TPM_HORPOSANIMATION As Integer = &H400
Private Const TPM_NOANIMATION As Integer = &H4000
Private Const TPM_VERNEGANIMATION As Integer = &H2000
Private Const TPM_VERPOSANIMATION As Integer = &H1000
///
"Mike Stephens" <mi**************@nopeasandham.yahoo.co.nz> wrote in message
news:ub**************@TK2MSFTNGP09.phx.gbl...
I don't want to position the context menu to the right of the button I
want to align it. I want both right hand sides to be in line with each other.
Part of my problem is I am unable to retrieve the width of the context
menu.
<an*******@discussions.microsoft.com> wrote in message
news:a0****************************@phx.gbl... Use the following code in the click event of the button:
System.Drawing.Point pos = new System.Drawing.Point
(yourButton.Width + 10, 0);
this.contextMenu1.Show(this.yourButton, pos);
This will show the context menu 10 pixels to right of the
button. You can set the height appropriately. The code
above aligns the top of the menu with the top of the
button.
Thanks
Nasser
-----Original Message-----
This is very simple and for the life of me the solution
escapes me.
How can I align a context menu to the right button of a
button?
Regards,
Mike
.