Click here to Skip to main content
11,583,532 members (72,433 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows WinForm
I have a simple form that has only a few controls on it. It will resize but only increase in size. What it up?
    private void InitializeComponent()
    {
      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDisplayResults));
      this.dataGrid = new System.Windows.Forms.DataGridView();
      this.panel1 = new System.Windows.Forms.Panel();
      this.statusIcon = new System.Windows.Forms.PictureBox();
      this.lableStatus = new System.Windows.Forms.Label();
      this.buttonOk = new System.Windows.Forms.Button();
      this.buttonCancel = new System.Windows.Forms.Button();
      ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).BeginInit();
      this.panel1.SuspendLayout();
      ((System.ComponentModel.ISupportInitialize)(this.statusIcon)).BeginInit();
      this.SuspendLayout();
      // 
      // dataGrid
      // 
      this.dataGrid.AllowUserToAddRows = false;
      this.dataGrid.AllowUserToDeleteRows = false;
      this.dataGrid.AllowUserToOrderColumns = true;
      this.dataGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
      this.dataGrid.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
      this.dataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
      this.dataGrid.Dock = System.Windows.Forms.DockStyle.Fill;
      this.dataGrid.Location = new System.Drawing.Point(0, 0);
      this.dataGrid.Name = "dataGrid";
      this.dataGrid.ReadOnly = true;
      this.dataGrid.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
      this.dataGrid.Size = new System.Drawing.Size(976, 572);
      this.dataGrid.TabIndex = 0;
      this.dataGrid.TabStop = false;
      // 
      // panel1
      // 
      this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
      this.panel1.Controls.Add(this.statusIcon);
      this.panel1.Controls.Add(this.lableStatus);
      this.panel1.Controls.Add(this.buttonOk);
      this.panel1.Controls.Add(this.buttonCancel);
      this.panel1.Location = new System.Drawing.Point(0, 547);
      this.panel1.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10);
      this.panel1.Name = "panel1";
      this.panel1.Size = new System.Drawing.Size(976, 25);
      this.panel1.TabIndex = 1;
      // 
      // statusIcon
      // 
      this.statusIcon.Image = ((System.Drawing.Image)(resources.GetObject("statusIcon.Image")));
      this.statusIcon.Location = new System.Drawing.Point(0, 0);
      this.statusIcon.Name = "statusIcon";
      this.statusIcon.Size = new System.Drawing.Size(24, 24);
      this.statusIcon.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
      this.statusIcon.TabIndex = 3;
      this.statusIcon.TabStop = false;
      // 
      // lableStatus
      // 
      this.lableStatus.AutoSize = true;
      this.lableStatus.Location = new System.Drawing.Point(32, 6);
      this.lableStatus.Margin = new System.Windows.Forms.Padding(5, 10, 5, 10);
      this.lableStatus.Name = "lableStatus";
      this.lableStatus.Size = new System.Drawing.Size(28, 13);
      this.lableStatus.TabIndex = 2;
      this.lableStatus.Text = "Text";
      // 
      // buttonOk
      // 
      this.buttonOk.Dock = System.Windows.Forms.DockStyle.Right;
      this.buttonOk.Location = new System.Drawing.Point(828, 0);
      this.buttonOk.Name = "buttonOk";
      this.buttonOk.Size = new System.Drawing.Size(73, 25);
      this.buttonOk.TabIndex = 1;
      this.buttonOk.Text = "Submit";
      this.buttonOk.UseVisualStyleBackColor = true;
      this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
      // 
      // buttonCancel
      // 
      this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
      this.buttonCancel.Dock = System.Windows.Forms.DockStyle.Right;
      this.buttonCancel.Location = new System.Drawing.Point(901, 0);
      this.buttonCancel.Margin = new System.Windows.Forms.Padding(5);
      this.buttonCancel.Name = "buttonCancel";
      this.buttonCancel.Size = new System.Drawing.Size(75, 25);
      this.buttonCancel.TabIndex = 0;
      this.buttonCancel.Text = "Cancel";
      this.buttonCancel.UseVisualStyleBackColor = true;
      this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
      // 
      // FormDisplayResults
      // 
      this.AcceptButton = this.buttonOk;
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.AutoSize = true;
      this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
      this.CancelButton = this.buttonCancel;
      this.CausesValidation = false;
      this.ClientSize = new System.Drawing.Size(976, 572);
      this.ControlBox = false;
      this.Controls.Add(this.panel1);
      this.Controls.Add(this.dataGrid);
      this.Name = "FormDisplayResults";
      this.Text = "Display Results";
      ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit();
      this.panel1.ResumeLayout(false);
      this.panel1.PerformLayout();
      ((System.ComponentModel.ISupportInitialize)(this.statusIcon)).EndInit();
      this.ResumeLayout(false);
 
    }
Posted 16-Aug-12 6:43am
Edited 16-Aug-12 7:22am
v2
Comments
Alan N at 16-Aug-12 13:15pm
   
Is the form's AutoSize property intentionally set to true?
Clifford Nelson at 16-Aug-12 13:21pm
   
Great catch, submit solution and I will say you solved it.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I was hoping that this was going to a problem about the complexities of AutoSizing, but perhaps you have just inadvertantly set AutoSize on the main form.

Alan!
  Permalink  
Comments
Clifford Nelson at 16-Aug-12 13:26pm
   
I am a WPF developer, have not really worked in WinForms in years. However right now working with Excel Add-In and putting WPF into Excel Add-in is just not worth the effort. Feel like I am back in the stone age.
Sergey Alexandrovich Kryukov at 16-Aug-12 16:26pm
   
Sure, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 1,403
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 696
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 503


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 16 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100