Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / December 2007

Tip: Looking for answers? Try searching our database.

Why isn't this easier?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff Johnson - 13 Dec 2007 16:08 GMT
The Control class offers a ContextMenuStrip so that you can assign a menu to
be automatically displayed when the control is right-clicked. That's nice.
Why then don't the more complex controls provide you with an easy way of
determining WHAT was clicked?

For example, I have a tree view. I want to go the easy route and assign a
ContextMenuStrip to it. Then, in the Click event of the ToolStripMenuItem,
there should be an EASY way of determining what brought the menu up in the
first place! For example, I should be able to determine if it was the tree
itself that was clicked or one of the nodes, and, if a node, WHICH node. Am
I missing a property somewhere or do I have to pull tricks (generally
involving MouseDown/Up) to figure out "where I am"?
Alex Blekhman - 13 Dec 2007 16:56 GMT
> The Control class offers a ContextMenuStrip so that you
> can assign a menu to be automatically displayed when the
> control is right-clicked. That's nice. Why then don't the
> more complex controls provide you with an easy way of
> determining WHAT was clicked?

Actually, they do. See `TreeView.HitTest' and
`TreeView.GetNodeAt' methods.

HTH
Alex
Jeff Johnson - 13 Dec 2007 18:57 GMT
>> The Control class offers a ContextMenuStrip so that you can assign a menu
>> to be automatically displayed when the control is right-clicked. That's
[quoted text clipped - 3 lines]
> Actually, they do. See `TreeView.HitTest' and `TreeView.GetNodeAt'
> methods.

No, that's not what I call easy; that's the code I'm expecting to have to
write. I think the tree view control should provide ContextMenuTarget and
ContextMenuTargetType properties which I can just reference directly from
the Click event of the menu item.
Alex Blekhman - 13 Dec 2007 20:25 GMT
>> Actually, they do. See `TreeView.HitTest' and
>> `TreeView.GetNodeAt' methods.
[quoted text clipped - 4 lines]
> properties which I can just reference directly from the
> Click event of the menu item.

But what if you need to display different context menus for
different tree nodes? Also, don't forget that WinForms
controls are rather thin wrappers on top of Win32 common
controls. So, they expose whatever underlying native control
delivers. Sometimes even less (see my rants in
"Icon.FromHandle + ImageList = decreased color depth"
thread, for example).

Alex

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.