From c62fb23f9981dfaa6089f27c8a5707b3f22c7583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Sun, 15 May 2011 21:43:40 +0000 Subject: [PATCH] Improved the selection dragging on the tree view. The selection moves now only when the dragging starts on the tree view. With the old implementation, double-clicking the gadget would change the selection, because the mouse is still pressed when the main window is shown. --- GUI/MainForm.Designer.cs | 2 ++ GUI/MainForm.cs | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/GUI/MainForm.Designer.cs b/GUI/MainForm.Designer.cs index 98e98be..335c7f9 100644 --- a/GUI/MainForm.Designer.cs +++ b/GUI/MainForm.Designer.cs @@ -463,7 +463,9 @@ namespace OpenHardwareMonitor.GUI { this.treeView.UseColumns = true; this.treeView.NodeMouseDoubleClick += new System.EventHandler(this.treeView_NodeMouseDoubleClick); this.treeView.Click += new System.EventHandler(this.treeView_Click); + this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown); this.treeView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseMove); + this.treeView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseUp); // // plotPanel // diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index b76a7a2..473f9d2 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -76,6 +76,8 @@ namespace OpenHardwareMonitor.GUI { private WmiProvider wmiProvider; + private bool selectionDragging = false; + public MainForm() { InitializeComponent(); @@ -629,9 +631,19 @@ namespace OpenHardwareMonitor.GUI { } private void treeView_MouseMove(object sender, MouseEventArgs e) { - if ((e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0) { - treeView.SelectedNode = treeView.GetNodeAt(e.Location); - } + selectionDragging = selectionDragging & + (e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0; + + if (selectionDragging) + treeView.SelectedNode = treeView.GetNodeAt(e.Location); + } + + private void treeView_MouseDown(object sender, MouseEventArgs e) { + selectionDragging = true; + } + + private void treeView_MouseUp(object sender, MouseEventArgs e) { + selectionDragging = false; } } }