表格布局面板未调整大小

时间:2013-12-27 08:36:18

标签: c# .net winforms

我有以下代码,我有Form,上面有Tabcontrol。在TabControl上,我有一个TabPage,其中我有一个TableLayoutPanel,其中包含3个TextBox和3个CheckBox。我已经尝试了所有可能的措施来调整TableLayoutPanel的大小,但它没有调整大小。如果有人指出我在代码中犯的错误会很好吗?我发布以下代码: -

         CheckBox TitleCheckBox = new CheckBox() ; 
        TitleCheckBox.Checked = false ; 
        TextBox TextBoxTitle = new TextBox() ; 
        TextBoxTitle.Size = new Size(200,50) ;
        TextBoxTitle.Text = "Enter the title of file or folder here.";
        CheckBox ExtensionCheckBox = new CheckBox();
        ExtensionCheckBox.Checked = false; 
        TextBox TextBoxExtension = new TextBox();
        TextBoxExtension.Size = new Size(200, 50);
        TextBoxExtension.Text = "Enter the extension for file here.";
        CheckBox SizeCheckBox = new CheckBox();
        SizeCheckBox.Checked = false;
        TextBox TextBoxSize = new TextBox();
        TextBoxSize.Text = "Enter the size for file or folder here.";
        TextBoxSize.Size = new Size(200, 50); 
        TableLayoutPanel LayoutPanelGeneral = new TableLayoutPanel() ; 
        LayoutPanelGeneral.RowCount = 3 ; 
        LayoutPanelGeneral.ColumnCount = 2; 
        LayoutPanelGeneral.RowStyles.Add(new RowStyle(SizeType.AutoSize)) ; 
        LayoutPanelGeneral.RowStyles.Add(new RowStyle(SizeType.AutoSize)) ; 
        LayoutPanelGeneral.RowStyles.Add(new RowStyle(SizeType.AutoSize)) ; 
        LayoutPanelGeneral.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)) ; 
        LayoutPanelGeneral.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)) ; 
        LayoutPanelGeneral.Controls.Add(TextBoxTitle, 0,0) ; 
        LayoutPanelGeneral.Controls.Add(TitleCheckBox, 1,0)  ;
        LayoutPanelGeneral.Controls.Add(TextBoxExtension, 0, 1);
        LayoutPanelGeneral.Controls.Add(ExtensionCheckBox, 1, 1);
        LayoutPanelGeneral.Controls.Add(TextBoxSize, 0, 2);
        LayoutPanelGeneral.Controls.Add(SizeCheckBox, 1, 2);
        TabControl AdvancedTabControl = new TabControl();
        TabPage TabPageGeneral = new TabPage();
        TabPageGeneral.Size = new System.Drawing.Size(1300, 800); 
        TabPageGeneral.Name = "TabPageGeneral";
        TabPageGeneral.Text = "General"; 
        Form AdvancedForm = new Form();
        AdvancedForm.Text = "Advanced Mode";
        AdvancedForm.MinimizeBox = false;
        AdvancedForm.MaximizeBox = false;
        TabPageGeneral.Size = AdvancedForm.Size;
        LayoutPanelGeneral.Size = TabPageGeneral.Size; 
        AdvancedForm.Controls.Add(AdvancedTabControl);
        AdvancedTabControl.TabPages.Add(TabPageGeneral); 
        TabPageGeneral.Controls.Add(LayoutPanelGeneral) ;
        AdvancedForm.ShowDialog() ; 

总的来说,我尝试了以下措施: -

1)更改width的{​​{1}}和height 2)将TableLayoutPanel设置为AutoSize;

1 个答案:

答案 0 :(得分:0)

遇到同样的问题并用以下方法解决:

((ISupportInitialize)(this.tabControl1)).BeginInit();

[...]

((ISupportInitialize)(this.tabControl1)).EndInit();