HighTechTalks DotNet Forums  

Why isn't this easier?

Dotnet Framework (WinForms Controls) microsoft.public.dotnet.framework.windowsforms.controls


Discuss Why isn't this easier? in the Dotnet Framework (WinForms Controls) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jeff Johnson
 
Posts: n/a

Default Why isn't this easier? - 12-13-2007 , 11:08 AM






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"?



Reply With Quote
  #2  
Old   
Alex Blekhman
 
Posts: n/a

Default Re: Why isn't this easier? - 12-13-2007 , 11:56 AM






"Jeff Johnson" wrote:
Quote:
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




Reply With Quote
  #3  
Old   
Jeff Johnson
 
Posts: n/a

Default Re: Why isn't this easier? - 12-13-2007 , 01:57 PM



"Alex Blekhman" <tkfx.REMOVE (AT) yahoo (DOT) com> wrote


Quote:
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.
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.




Reply With Quote
  #4  
Old   
Alex Blekhman
 
Posts: n/a

Default Re: Why isn't this easier? - 12-13-2007 , 03:25 PM



"Jeff Johnson" wrote:
Quote:
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.
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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.