473,385 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Align context menu to a button

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
Jul 21 '05 #1
3 2067
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
.

Jul 21 '05 #2
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
.

Jul 21 '05 #3
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
.


Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark | last post by:
Ok, it is starting to get somewhere, but i am not sure what to do with the following problem: I designed "knobs". They are 90px in width and do have one border (right) of 1px. So i guess, within...
4
by: Mohit Gupta | last post by:
Hi all, Lately I have been working on an application in VB .net CF for Pocket PC device. I have a small question about Context Menu. When I try to close the window after context menu is poped...
6
by: Michel | last post by:
Can I invoke the context menu from javascript so I can have it disabled on 1 right-click, but show it on a double right-click or vice-versa?
0
by: Derrick | last post by:
I'm trying to calculate the height of a context menu in a manner that will work in both the full framework (where the calculation is easier because of the MeasureItem event of a MenuItem) and the...
5
by: Dean L. Howen | last post by:
Dear friends, Could we determine when context menu should appear?
0
by: VP | last post by:
G'day folks, well i am attempting to get an understanding on how to create the menuitems in a context menu on the fly. So far I have managed to actually achieve the menu items being created for...
1
by: Dino Buljubasic | last post by:
Hi, I have a toolbar with several buttons on it, one of which is set up to be as a DropDown button. I also have a context menu with menu items assigend to it so when I click that button, my...
3
by: Mike Stephens | last post by:
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
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.