Fixed 鸟粪一样的TreeView下的NodeMouseDoubleClick Bug

时间:2023-01-07 23:34:20
  private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
Rectangle baseRectangle = this.treeView1.SelectedNode.Bounds;
Point mouseClickPoint = e.Location; if (this.treeView1.SelectedNode == e.Node) {
if (WasInBounds(baseRectangle, mouseClickPoint)) {
MessageBox.Show(string.Format("the selected node text:{0}", e.Node.Text));
}
}
} /// <summary>
/// Return a value indicating whether the click point belong the reactangle region.
/// </summary>
/// <param name="baseRectangle"></param>
/// <param name="clickPoint"></param>
/// <returns></returns>
private static bool WasInBounds(Rectangle baseRectangle, Point clickPoint) {
bool result = true; int bottom = baseRectangle.Bottom;
int right = baseRectangle.Right;
int left = baseRectangle.Left;
int top = baseRectangle.Top; if ((clickPoint.X < left || clickPoint.X > right) || (clickPoint.Y > bottom || clickPoint.Y < top)) {
result = false;
} return result;
}

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