Fixed 鸟粪一样的TreeView下的NodeMouseDoubleClick Bug

 1  private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {

 2             Rectangle baseRectangle = this.treeView1.SelectedNode.Bounds;

 3             Point mouseClickPoint = e.Location;

 4 

 5             if (this.treeView1.SelectedNode == e.Node) {

 6                 if (WasInBounds(baseRectangle, mouseClickPoint)) {

 7                     MessageBox.Show(string.Format("the selected node text:{0}", e.Node.Text));

 8                 }

 9             }

10         }

11 

12         /// <summary>

13         /// Return a value indicating whether the click point belong the reactangle region.

14         /// </summary>

15         /// <param name="baseRectangle"></param>

16         /// <param name="clickPoint"></param>

17         /// <returns></returns>

18         private static bool WasInBounds(Rectangle baseRectangle, Point clickPoint) {

19             bool result = true;

20 

21             int bottom = baseRectangle.Bottom;

22             int right = baseRectangle.Right;

23             int left = baseRectangle.Left;

24             int top = baseRectangle.Top;

25 

26             if ((clickPoint.X < left || clickPoint.X > right) || (clickPoint.Y > bottom || clickPoint.Y < top)) {

27                 result = false;

28             }

29 

30             return result;

31         }


废话不多说,用过的人看了代码自然明白

你可能感兴趣的:(treeview)