【发布时间】:2020-01-08 06:10:29
【问题描述】:
当拖动一个节点时,虽然我得到了移动图标,但在我的案例中没有显示工具提示文本,因为在给定的 SimpleExample 中使用了 Andrey Gliznetsov 的 TreeViewAdv。
这似乎不受添加 Tooltip 对象和使用 SetToolTip 方法的影响。拖动时如何让工具提示显示被拖动节点的文本(和图标)?
]
【问题讨论】:
当拖动一个节点时,虽然我得到了移动图标,但在我的案例中没有显示工具提示文本,因为在给定的 SimpleExample 中使用了 Andrey Gliznetsov 的 TreeViewAdv。
这似乎不受添加 Tooltip 对象和使用 SetToolTip 方法的影响。拖动时如何让工具提示显示被拖动节点的文本(和图标)?
]
【问题讨论】:
在TreeViewAdv.Input.cs,你会找到这个方法
private void CreateDragBitmap(IDataObject data)
{
if (UseColumns || !DisplayDraggingNodes)
return;
如果正在使用列,则会阻止创建 _dragBitmap。如果您必须使用未经修改的 TreeViewAdv 控件 dll,那么如果您想查看工具提示,唯一的解决方法是不使用列 (Property UseColumns = False)。
但由于提供了源代码,您可以修改 CreateDragBitmap,方法是从该方法中的第一个 if 语句中删除条件 UseColumns,并在 foreach NodeControl 循环中添加一个条件以在第一个绘制后退出:
private void CreateDragBitmap(IDataObject data)
{
if (!DisplayDraggingNodes) //removed UseColumns as OR condition here
return;
TreeNodeAdv[] nodes = data.GetData(typeof(TreeNodeAdv[])) as TreeNodeAdv[];
if (nodes != null && nodes.Length > 0)
{
Rectangle rect = DisplayRectangle;
Bitmap bitmap = new Bitmap(rect.Width, rect.Height);
using (Graphics gr = Graphics.FromImage(bitmap))
{
gr.Clear(BackColor);
DrawContext context = new DrawContext();
context.Graphics = gr;
context.Font = Font;
context.Enabled = true;
int y = 0;
int maxWidth = 0;
foreach (TreeNodeAdv node in nodes)
{
if (node.Tree == this)
{
int x = 0;
int height = _rowLayout.GetRowBounds(node.Row).Height;
foreach (NodeControl c in NodeControls)
{
Size s = c.GetActualSize(node, context);
if (!s.IsEmpty)
{
int width = s.Width;
rect = new Rectangle(x, y, width, height);
x += (width + 1);
context.Bounds = rect;
c.Draw(node, context);
if (UseColumns) //only show first column if using columns
break;
}
}
y += height;
maxWidth = Math.Max(maxWidth, x);
}
}
if (maxWidth > 0 && y > 0)
{
_dragBitmap = new Bitmap(maxWidth, y, PixelFormat.Format32bppArgb);
using (Graphics tgr = Graphics.FromImage(_dragBitmap))
tgr.DrawImage(bitmap, Point.Empty);
BitmapHelper.SetAlphaChanelValue(_dragBitmap, 150);
}
else
_dragBitmap = null;
}
}
}
导致
如果您想在拖动时查看所有列,请省略 if (UseColumns) break; 更改,如下所示
【讨论】: