From 855daf9d4325b74b689176f489ee8cb58e430c4d Mon Sep 17 00:00:00 2001 From: gobbo1008 Date: Fri, 15 Sep 2017 10:33:55 +0200 Subject: [PATCH] Fix for TreeView Fixes #1 --- ESOResearchNotifier/Form1.Designer.cs | 4 ++-- ESOResearchNotifier/Form1.cs | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ESOResearchNotifier/Form1.Designer.cs b/ESOResearchNotifier/Form1.Designer.cs index 40505cc..64c8699 100644 --- a/ESOResearchNotifier/Form1.Designer.cs +++ b/ESOResearchNotifier/Form1.Designer.cs @@ -37,7 +37,7 @@ private void InitializeComponent() this.menuItemMute = new System.Windows.Forms.ToolStripMenuItem(); this.menuItemExit = new System.Windows.Forms.ToolStripMenuItem(); this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.treeView1 = new System.Windows.Forms.TreeView(); + this.treeView1 = new FixedTreeView(); this.cboNotifyStyle = new System.Windows.Forms.ComboBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.cboTimeout = new System.Windows.Forms.ComboBox(); @@ -291,7 +291,7 @@ private void InitializeComponent() private System.Windows.Forms.FlowLayoutPanel panelResearch; private System.Windows.Forms.LinkLabel linkLabel2; private System.Windows.Forms.ToolTip toolTip1; - private System.Windows.Forms.TreeView treeView1; + private FixedTreeView treeView1; private System.Windows.Forms.GroupBox groupBox3; } } diff --git a/ESOResearchNotifier/Form1.cs b/ESOResearchNotifier/Form1.cs index b2e1bd9..27967fb 100644 --- a/ESOResearchNotifier/Form1.cs +++ b/ESOResearchNotifier/Form1.cs @@ -414,4 +414,31 @@ public class TreeMetaNode: TreeNode { public object MetaValue { get; set; } } + + public partial class FixedTreeView : TreeView + { + private const int WM_LBUTTONDBLCLK = 0x0203; + private const int WM_RBUTTONDOWN = 0x0204; + protected override void WndProc(ref Message m) + { + if (m.Msg == WM_LBUTTONDBLCLK) + { + // disable double-click on checkbox to fix Microsoft Vista bug + TreeViewHitTestInfo tvhti = HitTest(new System.Drawing.Point((int)m.LParam)); + if (tvhti != null && tvhti.Location == TreeViewHitTestLocations.StateImage) + { + m.Result = IntPtr.Zero; + return; + } + } + else if (m.Msg == WM_RBUTTONDOWN) + { + // set focus to node on right-click - another Microsoft bug? + TreeViewHitTestInfo tvhti = HitTest(new System.Drawing.Point((int)m.LParam)); + if (tvhti != null) + this.SelectedNode = tvhti.Node; + } + base.WndProc(ref m); + } + } } \ No newline at end of file