C#自定义树节点对齐
我有一个自定义TreeNode控件C#自定义树节点对齐,c#,treenode,C#,Treenode,我有一个自定义TreeNode控件 DrawMode = OwnerDrawAll 如果用户展开树,则需要增加与其他节点的距离。 就我而言,我看到了这一点 我添加了VisualElementRenderer(加号和减号) 和更多功能。 但无法找到一个很好的解决方案来增加距离 例如,我已经试过了 int offset = 20; e.Bound.X + offset * e.Node.Index; 我明白了 但是你不应该是对的 我的树是: 我的树 aaa |___ Nuova Carte
DrawMode = OwnerDrawAll
如果用户展开树,则需要增加与其他节点的距离。
就我而言,我看到了这一点
我添加了VisualElementRenderer(加号和减号)
和更多功能。
但无法找到一个很好的解决方案来增加距离
例如,我已经试过了
int offset = 20;
e.Bound.X + offset * e.Node.Index;
我明白了
但是你不应该是对的
我的树是:
我的树
aaa
|___ Nuova Cartella
| |_ Nuovo Documenti di testo.txt
|
|__ aaa.mp2d
|__ test.mp2d
我的代码
g.DrawString(e.Node.Text, this.Font, Brushes.Black, new PointF(e.Bounds.X + 40 + offset * e.Node.Index, e.Bounds.Y + 15));
if (e.Node.Text.Contains(".mp2d"))
{
if (anteprime.ContainsKey(e.Node.Text)) g.DrawImage(anteprime[e.Node.Text], e.Bounds.X+offset * e.Node.Index, e.Bounds.Y + 5);
else g.DrawImage(Properties.Resources.NoPreview, e.Bounds.X+offset * e.Node.Index, e.Bounds.Y + 5);
}
else
{
if (e.Node.IsExpanded)
{
g.DrawImage(MireEditor.Properties.Resources.folder_black, e.Bounds.X+offset * e.Node.Index, e.Bounds.Y + 5);
}
else
{
g.DrawImage(MireEditor.Properties.Resources.Folder_Black_Generic, e.Bounds.X+offset * e.Node.Index, e.Bounds.Y + 5);
}
如何正确绘制?
DrawTreeNodeEventArgs.Bounds
是只读属性;尝试这样做:Rectangle bounds=new Rectangle(e.bounds.X+offset*e.Node.Level,e.bounds.Y,e.bounds.Width,e.bounds.Height)
而不是使用e.Bounds.X
使用Bounds.X
您无法直接控制TreeView将其节点放置在何处。只能间接更改字体属性。点尺寸越大,节点之间的间距就越大。你实际上不必用那种字体来画画。@AlphaDelta-Tanks-Delta!工作精细,带矩形:)