473,395 Members | 1,554 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,395 software developers and data experts.

TreeView contextual menu location

Shouldn't this code put the menu in the same location as my cursor?

Point screenPoint = new Point(e.X, e.Y);
Point formPoint = treeView1.PointToClient(screenPoint);

Tree_ContextMenu.Show(this, formPoint);

I'm getting it above the cursor. From whay I read on MSDN about
pointToClient it shoud do what I want... but it's not. Any ideas?

Thanks,

Steve
Nov 16 '05 #1
2 1591
Steve,

I don't believe so. The Show method expects the Point parameter to be
in relation to the control that is passed in for the control parameter.

When you get X and Y from the MouseEventArgs instance in your event
handler, they are in the coordinates of the treeview already (assuming that
the event handler is for the tree view). Because of this, you want to omit
the call to PointToClient, and then pass screenPoint directly to the Show
method of the context menu.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SteveK" <as***@asdfasdfsd.com> wrote in message
news:Oc**************@TK2MSFTNGP09.phx.gbl...
Shouldn't this code put the menu in the same location as my cursor?

Point screenPoint = new Point(e.X, e.Y);
Point formPoint = treeView1.PointToClient(screenPoint);

Tree_ContextMenu.Show(this, formPoint);

I'm getting it above the cursor. From whay I read on MSDN about
pointToClient it shoud do what I want... but it's not. Any ideas?

Thanks,

Steve

Nov 16 '05 #2
I was trying too hard!... again! ;)

Your solution/explanation *almost* works... the menu is still above the
cursor, but only by about 30 pixels now. I suspect this might be something
else, I will read up adn look into my code to see why that is happening.

Thanks Nicholas!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl...
Steve,

I don't believe so. The Show method expects the Point parameter to be
in relation to the control that is passed in for the control parameter.

When you get X and Y from the MouseEventArgs instance in your event
handler, they are in the coordinates of the treeview already (assuming that the event handler is for the tree view). Because of this, you want to omit the call to PointToClient, and then pass screenPoint directly to the Show
method of the context menu.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"SteveK" <as***@asdfasdfsd.com> wrote in message
news:Oc**************@TK2MSFTNGP09.phx.gbl...
Shouldn't this code put the menu in the same location as my cursor?

Point screenPoint = new Point(e.X, e.Y);
Point formPoint = treeView1.PointToClient(screenPoint);

Tree_ContextMenu.Show(this, formPoint);

I'm getting it above the cursor. From whay I read on MSDN about
pointToClient it shoud do what I want... but it's not. Any ideas?

Thanks,

Steve


Nov 16 '05 #3

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

Similar topics

4
by: Dennis M. Marks | last post by:
Has anyone ever considered making a simulated contextual menu. I know that you can sometimes trap a right click or option click. Why not open up a window that would act as a menu when this happens?...
3
by: Steve | last post by:
Visual Studio 2003 .NET / C# I have a treeview object on a form which acts as the main menu controller for my application. the treeview is always in sight, and the form it is on acts as the...
4
by: Aaron Queenan | last post by:
How can I use the designer to add a context menu to a class which inherits from a control, e.g. treeview, without adding the context menu to a form? For example, to add a context menu with...
3
by: feel | last post by:
Goin' crazy with this recursive function ported from delphi... I send a string like DirA/ DirB /DirC but i get in the treeView each one in a new node.Cant get the child node....!! -DirA -DirB...
1
by: Shailendra Batham | last post by:
Hey guys I am using the IE Web controls treeview control. I popuplate the treeview with XML and it looks fine........... my question is how can I add a right click popup menu to the treeview...
3
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the...
0
by: Brian Keating | last post by:
hi there i've a test program that creates a treeview and destroys it over and over, i keep track of the gdi object count for the process and see if they are ok. However when i switch on...
4
by: Andrew Robinson | last post by:
I am using a TreeView to perform navigation and have a few nodes that need to generate a popup menu. For this, I use the SelectedNodeChanged event and then add the relevant "window.open" script to...
0
by: MrNobody | last post by:
I want to display different menu item options depending on what the user right-clicks on the tree. I cant figure out how though, I currently tried to create separate ContextMenu objects in a...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.