[英]How can I resize a TreeView during runtime in a Control
我正在嘗試在運行時調整TreeView
窗口的大小,但無法做到。 在我的程序中,我可以按一個按鈕, TreeView
作為彈出窗口打開。
TreeView
在Control
內部:
private Control parent;
mytree= new TreeView();
parent.Controls.Add(mytree);
我已經嘗試搜索任何調整大小的屬性,但是沒有運氣,我找不到在運行時調整樹大小的方法。
我能看到的唯一方法是刪除控件並將其放入Form
,然后可以使它看起來相同,但是我仍然想知道是否還有其他方法可以解決此問題,如果有人知道的話! 謝謝
將錨屬性分配給樹形視圖,以便它以窗體(或可能是他的子控件)調整大小
這是定位按鈕的示例:
// 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.