一、winform TreeView控件的实现方式。
/// <summary>
/// Handles the MouseMove event of the treeView1 control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
/// <remarks></remarks>
private void treeView1_MouseMove(object sender, MouseEventArgs e)
{
TreeView _TreeView = (TreeView)sender;
//通过鼠标的e.X和e.Y坐标来获取TreeNode。
TreeNode _Node = treeView1.GetNodeAt(e.X, e.Y);
if (_Node != null)
{
//防止出现闪烁。
if (_TreeView.Tag == null || !_TreeView.Tag.Equals(_Node))
{
_TreeView.Refresh();
Graphics _Graphics = Graphics.FromHwnd(_TreeView.Handle);
//_Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 255)), _Node.Bounds);
//重绘整行节点。
_Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 255)), new Rectangle(new Point(0, _Node.Bounds.Y), new Size(this.treeView1.Width, _Node.Bounds.Height)));
_Graphics.Dispose();
_TreeView.Tag = _Node;
}
}
}
参考文章:http://topic.csdn.net/u/20091216/14/8df3c649-fb8b-4ee5-89f2-6ab8ad03f9cf.html
二、winform Devexpress TreeList控件的实现方式。
/// <summary>
/// Handles the MouseMove event of the treeList1 control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
/// <remarks></remarks>
private void treeList1_MouseMove(object sender, MouseEventArgs e)
{
TreeList _TreeView = (TreeList)sender;
Point mousePosition = Control.MousePosition;
if (_TreeView.State == TreeListState.Regular)
{
TreeListHitInfo hitInfo = _TreeView.CalcHitInfo(new Point(e.X, e.Y));
if (hitInfo.HitInfoType == HitInfoType.Cell)
{
//_TreeView.SetFocusedNode(hitInfo.Node);
//根据鼠标的e.X和e.Y来获取TreeListNode;而不能直接通过 _TreeView.FocusedNode来获取。
TreeListNode _Node = hitInfo.Node;
//TreeListNode _Node = _TreeView.FocusedNode;// Winfrom 程序中这样获取的this.treeList1.GetNodeAt(e.X, e.Y);
Rectangle r = (_TreeView.ViewInfo.RowsInfo[_Node].Cells[0] as DevExpress.XtraTreeList.ViewInfo.CellInfo).Bounds;
if (_Node != null)
{
//if (!_Node.Checked)
//{
//防止出现闪烁。
if (_TreeView.Tag == null || !_TreeView.Tag.Equals(_Node))
{
_TreeView.Refresh();
Graphics _Graphics = Graphics.FromHwnd(_TreeView.Handle);
// _Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 255)), r);
//重绘整行节点。
_Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 255)), new Rectangle(new Point(0, r.Y), new Size(_TreeView.Width, r.Height)));
_Graphics.Dispose();
_TreeView.Tag = _Node;
}
//}
}
}
}
}
一、关于Devexpress控件的TreeListNode如何得到Point的问题。
可以参考http://www.devexpress.com/Support/Center/p/Q203877.aspx
二、关于Devexpress控件在MouseOver事件中如何得到当前鼠标的TreeListNode
可以参考http://community.devexpress.com/forums/t/82086.aspx
演示效果:演示Demo下载