Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#自定义树节点对齐_C#_Treenode - Fatal编程技术网

C#自定义树节点对齐

C#自定义树节点对齐,c#,treenode,C#,Treenode,我有一个自定义TreeNode控件 DrawMode = OwnerDrawAll 如果用户展开树,则需要增加与其他节点的距离。 就我而言,我看到了这一点 我添加了VisualElementRenderer(加号和减号) 和更多功能。 但无法找到一个很好的解决方案来增加距离 例如,我已经试过了 int offset = 20; e.Bound.X + offset * e.Node.Index; 我明白了 但是你不应该是对的 我的树是: 我的树 aaa |___ Nuova Carte

我有一个自定义TreeNode控件

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!工作精细,带矩形:)