【问题标题】:How can I resize a TreeView during runtime in a Control如何在控件运行时调整 TreeView 的大小
【发布时间】:2018-03-15 16:11:29
【问题描述】:

我正在尝试在运行时调整 TreeView 窗口的大小,但我做不到。 在我的程序中,我可以按下一个按钮,TreeView 作为弹出窗口打开。

TreeViewControl 内:

private Control parent;  

mytree= new TreeView();
parent.Controls.Add(mytree);

我已经尝试搜索任何调整大小的属性,但没有成功,我找不到在运行时调整树大小的方法。
我能看到的唯一方法是删除控件并将其放在Form 中,然后我可以让它看起来一样,但我仍然想知道是否有另一种方法可以解决这个问题,请如果有人知道! 谢谢

【问题讨论】:

  • 那个 sn-p 没有设置任何属性。喜欢大小。
  • 直接按大小或按锚定或按对接,也许将其放入 SplitContainer..

标签: c# .net winforms resize treeview


【解决方案1】:

将锚属性分配给树视图,以便它根据表单调整大小(或者可能是他的子控件)

这是锚定按钮的示例:

// Add a button to a form and set some of its common properties.
private void AddMyButton()
{
   // Create a button and add it to the form.
   Button button1 = new Button();

   // Anchor the button to the bottom right corner of the form
   button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);

   // Assign a background image.
   button1.BackgroundImage = imageList1.Images[0];

   // Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center;

   // Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size;

   // Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1;
   button1.TabStop = true;

   // Add a delegate to handle the Click event.
   button1.Click += new System.EventHandler(this.button1_Click);

   // Add the button to the form.
   this.Controls.Add(button1);
}

重要的部分是button1.Anchor,其中示例按钮锚定在窗口的右下角,因此它会在您调整大小时跟随窗口,但您可以锚定到窗口的所有侧面,它会随之调整大小。

尝试不同的事情,你就会明白的。 消息来源:MSDN

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-22
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 2015-01-19
    相关资源
    最近更新 更多