[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Middle Mouse clicking on a node in a TreeView

Posted on 2009-07-01
5
Medium Priority
?
620 Views
Last Modified: 2013-12-17
I have a TreeView in a Windows Forms application in VS2005.
I am trying to display a message if the MIDDLE mouse button is clicked.

IT works OK for left and for right.
Why will it not work for the middle mouse button?


private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            switch (e.Button)
            {
                case MouseButtons.Left:
                    MessageBox.Show("Left clicked");
                    break;
                case MouseButtons.Middle:
                    MessageBox.Show("Middle clicked"); //Code is not reached
                    break;
                case MouseButtons.None:
                    break;
                case MouseButtons.Right:
                    MessageBox.Show("Right clicked");
                    break;
                case MouseButtons.XButton1:
                    break;
                case MouseButtons.XButton2:
                    break;
                default:
                    break;
            }
        }

Open in new window

0
Comment
Question by:Dabas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24760488
I'm not sure why it doesn't work for MouseClick (perhaps it's a bug), but it does work if you use MouseDown or MouseUp instead.
0
 
LVL 27

Author Comment

by:Dabas
ID: 24760623
I need it to work on the node, thanks
0
 
LVL 15

Accepted Solution

by:
jinal earned 1600 total points
ID: 24761397

private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
MessageBox.Show(e.Button.ToString() + e.Node.Text);
}
private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Middle)
{
TreeNodeMouseClickEventArgs arg1 = new TreeNodeMouseClickEventArgs(treeView1.SelectedNode,MouseButtons.Middle,1,MousePosition.X,MousePosition.Y);
treeView1_NodeMouseClick(sender,arg1);
}
}
private void treeView1_NodeMouseHover(object sender, TreeNodeMouseHoverEventArgs e)
{
treeView1.SelectedNode = e.Node;
}
0
 
LVL 9

Assisted Solution

by:Rahul Goel ITIL
Rahul Goel ITIL earned 400 total points
ID: 24761520
Here I created a new custom control.you can use that
    class treeView : TreeView
    {
        public event EventHandler OnMiddleMouseClick; 
 
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x207)
            {
                if (OnMiddleMouseClick != null)
                    OnMiddleMouseClick(this, new EventArgs());
            }
            base.WndProc(ref m);
        }
    }

Open in new window

0
 
LVL 27

Author Comment

by:Dabas
ID: 24761692
jinal:

Your solution works, thanks!

Rahu_ketu:

Your solution also works, but I prefer jinal's as I can have all of the buttons handled in the one place. Also, the code lets me know which node has been clicked.

Dabas
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question