2010-08-10 67 views
1

我有一個TableLayoutPanel的問題,它填充了一個userControl(DockStyle.Fill)。我面臨一個麻煩,當這個控件被調整大小時,我需要所有的單元格來改變它們的大小,但是隻有最後一行和最後一列的大小發生了變化(所以整個tableLayoutPanel填充了控件)。我使用Bounds屬性更改此控制器大小。Scaling WinForms TableLayoutPanel

比方說,我寫了下面的代碼:

// creating tableLayoutPanel: 

private void createTableLayoutPanel(int count) 
{ 
    tableLayoutPanel = new TableLayoutPanel(); 
    tableLayoutPanel.MouseClick += new MouseEventHandler(this.observe_MouseClick); 
    tableLayoutPanel.AutoSize = true; 
    tableLayoutPanel.ColumnCount = 3; 
    tableLayoutPanel.RowCount = count; 
    tableLayoutPanel.Dock = DockStyle.Fill; 
    tableLayoutPanel.AutoSize = true; 
    this.Controls.Add(tableLayoutPanel); 
} 

// resizing: 

private void OnMouseWheel(MouseEventArgs e) 
{ 
    this.Bounds = new Rectangle(this.Location.X, this.Location.Y, (int)(this.Width*newScale),(int)(this.Height*newScale)); 
} 

感謝您的幫助。

回答

4

對於每一行,與SizeType = SizeType.PercentHeight = 100/tableLayoutPanel.RowCount添加到TableLayoutPanelRowStyles集合中的項。與ColumnStyles集合一樣。