I have a large form, with several hundred controls. When I open it in
the designer, the designer resizes the form, but does not adjust the
size of anchored controls in containers, thus corrupting them. With a
great deal of effort, I've managed to remove every control that isn't
needed to reproduce the problem.
To reproduce the problem, do the following:
1) Create a project with the code below. Note that tabGeneral is 690
pixels high, and it contains a grid that is 652 pixel high, and
anchored top and bottom.
2) Open the form in the designer.
3) In the code, note that the designer has adjusted the height of the
tab to 669 (apparently to accommodate the MainMenu), but has not
adjusted the height of the anchored grid.
How can I fix or work around this problem?
using System;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class Form1 : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
public Form1()
{
InitializeComponent();
tabSettings.SelectedTab = tabGeneral;
}
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if(disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.menuMain = new
System.Windows.Forms.MainMenu(this.components);
this.miFile = new System.Windows.Forms.MenuItem();
this.miExit = new System.Windows.Forms.MenuItem();
this.tabGeneral = new System.Windows.Forms.TabPage();
this.gridGeneral = new
System.Windows.Forms.DataGridView();
this.tabSettings = new System.Windows.Forms.TabControl();
this.tabGeneral.SuspendLayout();
((System.ComponentModel.ISupportInitialize)
(this.gridGeneral)).BeginInit();
this.tabSettings.SuspendLayout();
this.SuspendLayout();
//
// menuMain
//
this.menuMain.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.miFile});
//
// miFile
//
this.miFile.Index = 0;
this.miFile.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.miExit});
this.miFile.Text = "&File";
//
// miExit
//
this.miExit.Index = 0;
this.miExit.Text = "E&xit";
//
// tabGeneral
//
this.tabGeneral.Controls.Add(this.gridGeneral);
this.tabGeneral.Location = new System.Drawing.Point(4,
22);
this.tabGeneral.Name = "tabGeneral";
this.tabGeneral.Padding = new
System.Windows.Forms.Padding(3);
this.tabGeneral.Size = new System.Drawing.Size(910, 690);
this.tabGeneral.TabIndex = 1;
this.tabGeneral.Text = "General";
this.tabGeneral.UseVisualStyleBackColor = true;
//
// gridGeneral
//
this.gridGeneral.Anchor =
((System.Windows.Forms.AnchorStyles)
((((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.gridGeneral.Location = new System.Drawing.Point(6,
6);
this.gridGeneral.Name = "gridGeneral";
this.gridGeneral.Size = new System.Drawing.Size(898, 652);
this.gridGeneral.TabIndex = 0;
//
// tabSettings
//
this.tabSettings.Anchor =
((System.Windows.Forms.AnchorStyles)
((((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tabSettings.Controls.Add(this.tabGeneral);
this.tabSettings.Location = new System.Drawing.Point(12,
12);
this.tabSettings.Name = "tabSettings";
this.tabSettings.SelectedIndex = 0;
this.tabSettings.Size = new System.Drawing.Size(918, 695);
this.tabSettings.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(942, 732);
this.Controls.Add(this.tabSettings);
this.Menu = this.menuMain;
this.Name = "Form1";
this.Text = "Product Settings";
this.tabGeneral.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)
(this.gridGeneral)).EndInit();
this.tabSettings.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.MainMenu menuMain;
private System.Windows.Forms.MenuItem miFile;
private System.Windows.Forms.MenuItem miExit;
private System.Windows.Forms.TabPage tabGeneral;
private System.Windows.Forms.DataGridView gridGeneral;
private System.Windows.Forms.TabControl tabSettings;
}
}