Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.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#_Winforms_User Interface_Treeview - Fatal编程技术网

C# 如何计算和更改树视图宽度

C# 如何计算和更改树视图宽度,c#,winforms,user-interface,treeview,C#,Winforms,User Interface,Treeview,如何让TreeView在展开节点时更改其宽度,以使节点的标签完全显示出来 首先,我设置DrawMode=OwnerDrawAll 然后在处理程序中处理事件DrawNodeandin e.DrawDefault = true; currentWith_ = Math.Max(currentWith_, e.Node.Bounds.Right); 然后在AfterExpand中使用设置控件。但并非每次都有效。有时,with未更改或更改不正确 如何纠正这个问题。 提前感谢。试试这个,它可以成功地工作

如何让
TreeView
在展开节点时更改其宽度,以使节点的标签完全显示出来

首先,我设置
DrawMode=OwnerDrawAll

然后在处理程序中处理事件
DrawNode
andin

e.DrawDefault = true;
currentWith_ = Math.Max(currentWith_, e.Node.Bounds.Right);
然后在
AfterExpand
中使用设置控件。但并非每次都有效。有时,with未更改或更改不正确

如何纠正这个问题。
提前感谢。

试试这个,它可以成功地工作:

private void treeViewAfterExpand(object sender, TreeViewEventArgs e)
{
    int maxRight = treeView.ClientSize.Width;

    if(e.Node.Nodes != null)
        foreach (TreeNode node in e.Node.Nodes)
        {
            maxRight = Math.Max(maxRight, node.Bounds.Right);
        }

    treeView.ClientSize = new Size(maxRight, treeView.ClientSize.Height);
}

Ria给出的解决方案是有效的,但在构造函数中进行扩展时不起作用。在load事件中扩展而不是在构造函数中扩展使其工作。(由于低于50分,无法发表评论。)

您尝试了什么?
treeView.Bounds
treeView.ClientSize
添加了边框等。不起作用!!!!只有集合中的第一个节点具有要设置的Bounds属性,另一个值设置为0。树中的每个节点都具有Bounds属性。您只需将treeview的大小设置为最大绑定宽度。是否尝试过?它们有边界属性,但其属性(宽度、高度等)设置为0!解决方案在
OnLoad
构造函数中也不起作用。是否存在缺陷或问题?有解决办法吗?