TableLayoutPanel isn't showing padding on bottom when scrollbar is visible - c#

I'm trying to build "dashboard" like layout for my WinForms application.
I was able to build simple concept using TableLayoutPanel.
I'm able to add columns, rows and controls to tlp (TableLayoutPanel), but I get unwanted behaviour:
I have padding set to 5 on tlp, but after adding two rows that padding disappears - I can scroll to bottom, but I'd like that padding to be visible when scrollbar is at bottom.
I'm adding new row with this code:
private void newButton_Click(object sender, EventArgs e)
{
var x = tableLayoutPanel1.RowStyles.Count - 1;
tableLayoutPanel1.RowStyles.Insert(x,new RowStyle(SizeType.Absolute,100));
var b = new Button
{
Dock = DockStyle.Fill,
Text = "New"+x.ToString(),
UseVisualStyleBackColor = true
};
tableLayoutPanel1.RowCount++;
x = tableLayoutPanel1.RowStyles.Count - 2;
tableLayoutPanel1.Controls.Add(b,0,x);
}
Is this behaviour by design or can I change it? Basically I'd like that bottom padding to be visible when I scroll to bottom on tlp.
As requested this is my tlp design code:
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.AutoScroll = true;
this.tableLayoutPanel1.AutoScrollMargin = new System.Drawing.Size(10, 10);
this.tableLayoutPanel1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.button1, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.button2, 1, 0);
this.tableLayoutPanel1.Cursor = System.Windows.Forms.Cursors.Default;
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 12);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.Padding = new System.Windows.Forms.Padding(5);
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(459, 221);
this.tableLayoutPanel1.TabIndex = 0;
//
// button1 - button in top left cell in tlp
//
this.button1.Dock = System.Windows.Forms.DockStyle.Fill;
this.button1.Location = new System.Drawing.Point(8, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(218, 94);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// button2 - button in top right cell in tlp
//
this.button2.Dock = System.Windows.Forms.DockStyle.Fill;
this.button2.Location = new System.Drawing.Point(232, 8);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(219, 94);
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
//
// button5 - "Test" button
//
this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button5.Location = new System.Drawing.Point(12, 427);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(75, 23);
this.button5.TabIndex = 1;
this.button5.Text = "Test";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(755, 462);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.button5);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
}
At first I have 2 rows, first set to 100 pixels absolute size, second to autofill, when I click "Test" button I'm inserting row that has same properties as first (absolute size, 100 px height)

Thanks to #Sinatr and #TaW I've solved my problem.
As You may see after adding more rows and scrolling to bottom padding is still visible (desirable effect).
The key was to put TableLayoutPanel inside UserControl.
Here are properties that must be set:
TableLayoutPanel (inside UserControl):
Dock:Top
AutoSize:True
AutoScroll:False
UserControl:
AutoScroll:True
Below is designer code from my UserControl:
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.AutoSize = true;
this.tableLayoutPanel1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.tableLayoutPanel1.ColumnCount = 3;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.34F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33F));
this.tableLayoutPanel1.Cursor = System.Windows.Forms.Cursors.Default;
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Top;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.Padding = new System.Windows.Forms.Padding(5);
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(443, 10);
this.tableLayoutPanel1.TabIndex = 1;
//
// Dashboard
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.BackColor = System.Drawing.Color.Transparent;
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Dashboard";
this.Size = new System.Drawing.Size(443, 208);
this.Load += new System.EventHandler(this.Dashboard_Load);
this.MouseEnter += new System.EventHandler(this.Dashboard_MouseEnter);
this.ResumeLayout(false);
this.PerformLayout();
}
I hope this help anyone having same problem.

Related

How can I make datagridviews not collide with button when I'm resizing form?

I have form in WinForms that looks like
this
I want the user to be able to resize the form. Buttons would stay the same size and datagridviews would grow when he does this.
Right now, datagridviews are colliding with buttons and It looks pretty ugly.
I want datagridviews to grow, but not collide with buttons.
I've tried many different combinations of code and It doesn't work like I wanted.
I want buttons to be between datagridviews.
Designer:
//
// dataGridView1
//
this.dataGridView1.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.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(13, 60);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowTemplate.Height = 24;
this.dataGridView1.Size = new System.Drawing.Size(291, 326);
this.dataGridView1.TabIndex = 0;
//
// dataGridView2
//
this.dataGridView2.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.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView2.Location = new System.Drawing.Point(566, 60);
this.dataGridView2.Name = "dataGridView2";
this.dataGridView2.RowTemplate.Height = 24;
this.dataGridView2.Size = new System.Drawing.Size(284, 326);
this.dataGridView2.TabIndex = 1;
//
// button1
//
this.button1.Anchor = System.Windows.Forms.AnchorStyles.None;
this.button1.Location = new System.Drawing.Point(375, 93);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(121, 83);
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// button2
//
this.button2.Anchor = System.Windows.Forms.AnchorStyles.None;
this.button2.Location = new System.Drawing.Point(375, 187);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(121, 83);
this.button2.TabIndex = 3;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
//
// button3
//
this.button3.Anchor = System.Windows.Forms.AnchorStyles.None;
this.button3.Location = new System.Drawing.Point(375, 281);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(121, 83);
this.button3.TabIndex = 4;
this.button3.Text = "button3";
this.button3.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(862, 398);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataGridView2);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
this.ResumeLayout(false);
Try a TableLayoutPanel. You can define 3 columns, the first one set to 50%, the second one to the width of your buttons (or set to AutoSize, initially set it to an absolute or percentage value, then place your buttons. One placed go back and change to autosize otherwise the column will shrink to nothing if there's nothing in the column) and the third to 50%. Then you'll need at least 3 rows, 1 row per button.
Put your first DataGridView in Cell 0,0 (Col 0, Row 0) and set RowSpan to 3. Put your second DataGridView in Cell 2,0 (Col 2, Row 0) and, again, set RowSpan to 3. Then in the middle column (col 1) put your 3 buttons, one in each row. You can remove anchoring at that point so the buttons float in the middle of the column. Set your datagridviews to DockStyle.Fill and you shouldn't have any issues with the DataGridRow overlapping the buttons.
Here's a couple of screenshots.
Use the Anchor Property to your Datagridview and buttons.

WinForms Docking Fill property is being ignored on window downsize, but not upsize

I have the following basic WinForm:
After scaling the form to a larger size than this designer view, all the controls adapt to the new height/width requirements of the parent containers just fine.
All docking properties for the form controls are set to Fill each parent container. However, when the form is resized to smaller than the 'Designer' view, controls do not get resized correctly. See below:
I have checked for MinimumSize properties on all controls and this does not appear to be the problem. Designer code:
private void InitializeComponent()
{
this.grpTasks = new System.Windows.Forms.GroupBox();
this.tbTillButtons = new System.Windows.Forms.TableLayoutPanel();
this.grpTransaction = new System.Windows.Forms.GroupBox();
this.tableTransaction = new System.Windows.Forms.TableLayoutPanel();
this.ctrlAddMemo = new System.Windows.Forms.Button();
this.ctrlFindbtn = new System.Windows.Forms.Button();
this.ctrlPrint = new System.Windows.Forms.Button();
this.ctrlVoidLine = new System.Windows.Forms.Button();
this.ctrlFinish = new System.Windows.Forms.Button();
this.ctrlVoidall = new System.Windows.Forms.Button();
this.grpOtherTasks = new System.Windows.Forms.GroupBox();
this.tableCashDrawer = new System.Windows.Forms.TableLayoutPanel();
this.ctrlAddCash = new System.Windows.Forms.Button();
this.ctrlRemoveCash = new System.Windows.Forms.Button();
this.ctrlOpenDraw = new System.Windows.Forms.Button();
this.ctrlReconcile = new System.Windows.Forms.Button();
this.grpPayFor = new System.Windows.Forms.GroupBox();
this.tablePayFor = new System.Windows.Forms.TableLayoutPanel();
this.cmdBooking = new System.Windows.Forms.Button();
this.cmdInvoice = new System.Windows.Forms.Button();
this.grpTasks.SuspendLayout();
this.tbTillButtons.SuspendLayout();
this.grpTransaction.SuspendLayout();
this.tableTransaction.SuspendLayout();
this.grpOtherTasks.SuspendLayout();
this.tableCashDrawer.SuspendLayout();
this.grpPayFor.SuspendLayout();
this.tablePayFor.SuspendLayout();
this.SuspendLayout();
//
// grpTasks
//
this.grpTasks.Controls.Add(this.tbTillButtons);
this.grpTasks.Dock = System.Windows.Forms.DockStyle.Fill;
this.grpTasks.Location = new System.Drawing.Point(0, 0);
this.grpTasks.Name = "grpTasks";
this.grpTasks.TabIndex = 0;
this.grpTasks.TabStop = false;
this.grpTasks.Text = "Tasks";
//
// tbTillButtons
//
this.tbTillButtons.AutoSize = true;
this.tbTillButtons.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tbTillButtons.ColumnCount = 3;
this.tbTillButtons.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15.22492F));
this.tbTillButtons.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30.92374F));
this.tbTillButtons.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 53.85135F));
this.tbTillButtons.Controls.Add(this.grpTransaction, 2, 0);
this.tbTillButtons.Controls.Add(this.grpOtherTasks, 1, 0);
this.tbTillButtons.Controls.Add(this.grpPayFor, 0, 0);
this.tbTillButtons.Dock = System.Windows.Forms.DockStyle.Fill;
this.tbTillButtons.Location = new System.Drawing.Point(3, 16);
this.tbTillButtons.Name = "tbTillButtons";
this.tbTillButtons.RowCount = 1;
this.tbTillButtons.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tbTillButtons.TabIndex = 0;
//
// grpTransaction
//
this.grpTransaction.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.grpTransaction.Controls.Add(this.tableTransaction);
this.grpTransaction.Dock = System.Windows.Forms.DockStyle.Fill;
this.grpTransaction.Location = new System.Drawing.Point(430, 3);
this.grpTransaction.Name = "grpTransaction";
this.grpTransaction.Size = new System.Drawing.Size(494, 386);
this.grpTransaction.TabIndex = 2;
this.grpTransaction.TabStop = false;
this.grpTransaction.Text = "Transaction";
//
// tableTransaction
//
this.tableTransaction.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableTransaction.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.tableTransaction.ColumnCount = 3;
this.tableTransaction.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableTransaction.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableTransaction.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableTransaction.Controls.Add(this.ctrlAddMemo, 0, 0);
this.tableTransaction.Controls.Add(this.ctrlFindbtn, 1, 0);
this.tableTransaction.Controls.Add(this.ctrlPrint, 0, 1);
this.tableTransaction.Controls.Add(this.ctrlVoidLine, 1, 1);
this.tableTransaction.Controls.Add(this.ctrlFinish, 2, 0);
this.tableTransaction.Controls.Add(this.ctrlVoidall, 2, 1);
this.tableTransaction.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableTransaction.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.tableTransaction.Location = new System.Drawing.Point(3, 16);
this.tableTransaction.Name = "tableTransaction";
this.tableTransaction.RowCount = 2;
this.tableTransaction.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableTransaction.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableTransaction.Size = new System.Drawing.Size(488, 367);
this.tableTransaction.TabIndex = 2;
//
// ctrlAddMemo
//
this.ctrlAddMemo.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlAddMemo.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlAddMemo.Location = new System.Drawing.Point(3, 3);
this.ctrlAddMemo.Name = "ctrlAddMemo";
this.ctrlAddMemo.Size = new System.Drawing.Size(156, 177);
this.ctrlAddMemo.TabIndex = 0;
this.ctrlAddMemo.Text = "button7";
this.ctrlAddMemo.UseVisualStyleBackColor = true;
//
// ctrlFindbtn
//
this.ctrlFindbtn.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlFindbtn.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlFindbtn.Location = new System.Drawing.Point(165, 3);
this.ctrlFindbtn.Name = "ctrlFindbtn";
this.ctrlFindbtn.Size = new System.Drawing.Size(156, 177);
this.ctrlFindbtn.TabIndex = 1;
this.ctrlFindbtn.Text = "button8";
this.ctrlFindbtn.UseVisualStyleBackColor = true;
//
// ctrlPrint
//
this.ctrlPrint.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlPrint.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlPrint.Location = new System.Drawing.Point(3, 186);
this.ctrlPrint.Name = "ctrlPrint";
this.ctrlPrint.Size = new System.Drawing.Size(156, 178);
this.ctrlPrint.TabIndex = 2;
this.ctrlPrint.Text = "button9";
this.ctrlPrint.UseVisualStyleBackColor = true;
//
// ctrlVoidLine
//
this.ctrlVoidLine.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlVoidLine.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlVoidLine.Location = new System.Drawing.Point(165, 186);
this.ctrlVoidLine.Name = "ctrlVoidLine";
this.ctrlVoidLine.Size = new System.Drawing.Size(156, 178);
this.ctrlVoidLine.TabIndex = 3;
this.ctrlVoidLine.Text = "button10";
this.ctrlVoidLine.UseVisualStyleBackColor = true;
//
// ctrlFinish
//
this.ctrlFinish.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlFinish.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlFinish.Location = new System.Drawing.Point(327, 3);
this.ctrlFinish.Name = "ctrlFinish";
this.ctrlFinish.Size = new System.Drawing.Size(158, 177);
this.ctrlFinish.TabIndex = 4;
this.ctrlFinish.Text = "button11";
this.ctrlFinish.UseVisualStyleBackColor = true;
//
// ctrlVoidall
//
this.ctrlVoidall.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlVoidall.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlVoidall.Location = new System.Drawing.Point(327, 186);
this.ctrlVoidall.Name = "ctrlVoidall";
this.ctrlVoidall.Size = new System.Drawing.Size(158, 178);
this.ctrlVoidall.TabIndex = 5;
this.ctrlVoidall.Text = "button12";
this.ctrlVoidall.UseVisualStyleBackColor = true;
//
// grpOtherTasks
//
this.grpOtherTasks.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.grpOtherTasks.Controls.Add(this.tableCashDrawer);
this.grpOtherTasks.Dock = System.Windows.Forms.DockStyle.Fill;
this.grpOtherTasks.Location = new System.Drawing.Point(144, 3);
this.grpOtherTasks.Name = "grpOtherTasks";
this.grpOtherTasks.Size = new System.Drawing.Size(280, 386);
this.grpOtherTasks.TabIndex = 1;
this.grpOtherTasks.TabStop = false;
this.grpOtherTasks.Text = "Cash Drawer";
//
// tableCashDrawer
//
this.tableCashDrawer.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableCashDrawer.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.tableCashDrawer.ColumnCount = 2;
this.tableCashDrawer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableCashDrawer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableCashDrawer.Controls.Add(this.ctrlAddCash, 0, 1);
this.tableCashDrawer.Controls.Add(this.ctrlRemoveCash, 0, 1);
this.tableCashDrawer.Controls.Add(this.ctrlOpenDraw, 1, 0);
this.tableCashDrawer.Controls.Add(this.ctrlReconcile, 0, 0);
this.tableCashDrawer.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableCashDrawer.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.tableCashDrawer.Location = new System.Drawing.Point(3, 16);
this.tableCashDrawer.Name = "tableCashDrawer";
this.tableCashDrawer.RowCount = 2;
this.tableCashDrawer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableCashDrawer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableCashDrawer.Size = new System.Drawing.Size(274, 367);
this.tableCashDrawer.TabIndex = 1;
//
// ctrlAddCash
//
this.ctrlAddCash.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlAddCash.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlAddCash.Location = new System.Drawing.Point(3, 186);
this.ctrlAddCash.Name = "ctrlAddCash";
this.ctrlAddCash.Size = new System.Drawing.Size(131, 178);
this.ctrlAddCash.TabIndex = 4;
this.ctrlAddCash.Text = "button6";
this.ctrlAddCash.UseVisualStyleBackColor = true;
//
// ctrlRemoveCash
//
this.ctrlRemoveCash.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlRemoveCash.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlRemoveCash.Location = new System.Drawing.Point(140, 186);
this.ctrlRemoveCash.Name = "ctrlRemoveCash";
this.ctrlRemoveCash.Size = new System.Drawing.Size(131, 178);
this.ctrlRemoveCash.TabIndex = 3;
this.ctrlRemoveCash.Text = "button5";
this.ctrlRemoveCash.UseVisualStyleBackColor = true;
//
// ctrlOpenDraw
//
this.ctrlOpenDraw.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlOpenDraw.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlOpenDraw.Location = new System.Drawing.Point(140, 3);
this.ctrlOpenDraw.Name = "ctrlOpenDraw";
this.ctrlOpenDraw.Size = new System.Drawing.Size(131, 177);
this.ctrlOpenDraw.TabIndex = 2;
this.ctrlOpenDraw.Text = "button3";
this.ctrlOpenDraw.UseVisualStyleBackColor = true;
//
// ctrlReconcile
//
this.ctrlReconcile.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlReconcile.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlReconcile.Location = new System.Drawing.Point(3, 3);
this.ctrlReconcile.Name = "ctrlReconcile";
this.ctrlReconcile.Size = new System.Drawing.Size(131, 177);
this.ctrlReconcile.TabIndex = 1;
this.ctrlReconcile.Text = "button4";
this.ctrlReconcile.UseVisualStyleBackColor = true;
//
// grpPayFor
//
this.grpPayFor.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.grpPayFor.Controls.Add(this.tablePayFor);
this.grpPayFor.Dock = System.Windows.Forms.DockStyle.Fill;
this.grpPayFor.Location = new System.Drawing.Point(3, 3);
this.grpPayFor.Name = "grpPayFor";
this.grpPayFor.Size = new System.Drawing.Size(135, 386);
this.grpPayFor.TabIndex = 0;
this.grpPayFor.TabStop = false;
this.grpPayFor.Text = "Pay for";
//
// tablePayFor
//
this.tablePayFor.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tablePayFor.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.tablePayFor.ColumnCount = 1;
this.tablePayFor.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tablePayFor.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tablePayFor.Controls.Add(this.cmdBooking, 0, 1);
this.tablePayFor.Controls.Add(this.cmdInvoice, 0, 0);
this.tablePayFor.Dock = System.Windows.Forms.DockStyle.Fill;
this.tablePayFor.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.tablePayFor.Location = new System.Drawing.Point(3, 16);
this.tablePayFor.Name = "tablePayFor";
this.tablePayFor.RowCount = 2;
this.tablePayFor.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tablePayFor.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tablePayFor.Size = new System.Drawing.Size(129, 367);
this.tablePayFor.TabIndex = 0;
//
// cmdBooking
//
this.cmdBooking.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.cmdBooking.Dock = System.Windows.Forms.DockStyle.Fill;
this.cmdBooking.Location = new System.Drawing.Point(3, 186);
this.cmdBooking.Name = "cmdBooking";
this.cmdBooking.Size = new System.Drawing.Size(123, 178);
this.cmdBooking.TabIndex = 2;
this.cmdBooking.Text = "button2";
this.cmdBooking.UseVisualStyleBackColor = true;
//
// cmdInvoice
//
this.cmdInvoice.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.cmdInvoice.Dock = System.Windows.Forms.DockStyle.Fill;
this.cmdInvoice.Location = new System.Drawing.Point(3, 3);
this.cmdInvoice.Name = "cmdInvoice";
this.cmdInvoice.Size = new System.Drawing.Size(123, 177);
this.cmdInvoice.TabIndex = 1;
this.cmdInvoice.Text = "button1";
this.cmdInvoice.UseVisualStyleBackColor = true;
//
// Main Form
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(933, 411);
this.Controls.Add(this.grpTasks);
this.Name = "Main Form";
this.Text = "Form1";
this.grpTasks.ResumeLayout(false);
this.grpTasks.PerformLayout();
this.tbTillButtons.ResumeLayout(false);
this.grpTransaction.ResumeLayout(false);
this.tableTransaction.ResumeLayout(false);
this.grpOtherTasks.ResumeLayout(false);
this.tableCashDrawer.ResumeLayout(false);
this.grpPayFor.ResumeLayout(false);
this.tablePayFor.ResumeLayout(false);
this.ResumeLayout(false);
}
Any ideas?
For anyone else with the same problem, I solved this issue by setting each button control's AutoSize property to True.
It now resizes whilst both upscaling and downscaling without a problem.

Resize 4 picture boxes when form is resized

I am implementing a winform application in c# so that it contains four picture boxes and some control buttons in one corner.
My main problem is that I cannot achieve the behaviour shown in the picture. The idea is to automatically resize the picture boxes when the form is resized. The area of the control panel should stay the same and only the area containing the boxes should be resized accordingly.
I have been playing with anchor and dock properties but I dont get the desire output.
Anyone could give me a hint?
Thanks and kind regards,
Bilbinight
So, let's say you have the following picture boxes:
pictureBox1 | pictureBox2 | panel
------------|------------
pictureBox3 | pictureBox4
Then the following should do the trick:
set the forms Resize event to this eventhandler:
private void Form1_Resize(object sender, EventArgs e)
{
int spaceBetweenPictures = 19;
int widthToFill = (this.Width - 40 - panel.Width) - spaceBetweenPictures;
int heightToFill = this.Height - 80;
pictureBox1.Width = widthToFill / 2;
pictureBox1.Height = heightToFill / 2;
// Setting the sizes of all the three pictureboxes to the sizes of the first one.
pictureBox2.Width = pictureBox1.Width;
pictureBox2.Height = pictureBox1.Height;
pictureBox3.Width = pictureBox1.Width;
pictureBox3.Height = pictureBox1.Height;
pictureBox4.Width = pictureBox1.Width;
pictureBox4.Height = pictureBox1.Height;
// Setting the positions:
pictureBox2.Location = new Point(pictureBox1.Width + spaceBetweenPictures, pictureBox1.Location.Y);
pictureBox3.Location = new Point(pictureBox1.Location.X, pictureBox1.Height + spaceBetweenPictures);
pictureBox4.Location = new Point(pictureBox2.Location.X, pictureBox3.Location.Y);
}
Of course you should modify the magic numbers in this code (19, 40, 80) accordingly, to suit your program (that depends a lot on whether you use border on your form or not).
UPDATE:
If you want your pictureboxes square shaped then just ignore the heightToFill variable and use widthToFill instead when setting the Height of pictureBox1. Or set:
pictureBox1.Height = pictureBox.Width;
And I also forgot to mention that the panel of course should be aligned Top, Right. So set the panel's Anchor property to:
AnchorStyles.Top | AnchorStyles.Right;
Are four image boxes supposed to support resizing at runtime (allowing end user to resize)? if not then following will give you desired result.
1 TableLayoutPanel with 2 rows and two columns. Set the initial size to fill the desired area, set the anchor to all four directions.
Add 4 picture boxes to 4 cells and set Dock to Fill for all Picture Boxes.
Add a panel to the right side of form, and make it fit to cover your controls area. Set the anchor Top, Bottom, Right.
Here is sample code:
//frmResizing.cs
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class frmResizing : Form
{
public frmResizing()
{
InitializeComponent();
}
}
}
//frmResizing.Designer.cs code
namespace WindowsFormsApplication1
{
partial class frmResizing
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.panel1 = new System.Windows.Forms.Panel();
this.pictureBox4 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.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.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.pictureBox4, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.pictureBox3, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.pictureBox2, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.pictureBox1, 0, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(2, 1);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(544, 561);
this.tableLayoutPanel1.TabIndex = 0;
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackColor = System.Drawing.Color.Red;
this.panel1.Location = new System.Drawing.Point(553, 1);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(107, 561);
this.panel1.TabIndex = 1;
//
// pictureBox4
//
this.pictureBox4.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox4.Image = global::WindowsFormsApplication1.Properties.Resources.download;
this.pictureBox4.Location = new System.Drawing.Point(275, 283);
this.pictureBox4.Name = "pictureBox4";
this.pictureBox4.Size = new System.Drawing.Size(266, 275);
this.pictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox4.TabIndex = 3;
this.pictureBox4.TabStop = false;
//
// pictureBox3
//
this.pictureBox3.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox3.Image = global::WindowsFormsApplication1.Properties.Resources.pizza_page;
this.pictureBox3.Location = new System.Drawing.Point(3, 283);
this.pictureBox3.Name = "pictureBox3";
this.pictureBox3.Size = new System.Drawing.Size(266, 275);
this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox3.TabIndex = 2;
this.pictureBox3.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox2.Image = global::WindowsFormsApplication1.Properties.Resources.images;
this.pictureBox2.Location = new System.Drawing.Point(275, 3);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(266, 274);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Image = global::WindowsFormsApplication1.Properties.Resources.download__1_;
this.pictureBox1.Location = new System.Drawing.Point(3, 3);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(266, 274);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(660, 562);
this.Controls.Add(this.panel1);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form2";
this.Text = "Form2";
this.tableLayoutPanel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.PictureBox pictureBox4;
private System.Windows.Forms.PictureBox pictureBox3;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Panel panel1;
}
}

Winforms DataGridView resizing issue

I'm not 100% sure how I should word this question but I'll try my best.
I have a PointCtrlForm that has a DataGridView inside a TableLayoutPanel. The DataGridView is docked to the table as Fill. PointCtrlForm is docked to another window set as MDIParent with the dockstyle property set as Fill.
Resizing the main window properly resizes the PointCtrlForm, which then is supposed to resize the DataGridView as well. Well, at least "half" of the resizing works properly. Enlarging the main window also enlarges the datagridview, which is what I expected but if I shrink the main window to a certain point, the DataGridView stops shrinking and hides the columns without showing a scrollbar.
I've checked that all columns do not have Frozen property enabled, checked that both the datagridview and the child window is properly docked, and checked the scrollbars property is set to both.
Edit: AutoSizeColumnsMode is also fill.
I'll post the content of the Designer.cs here. I'd appreciate any guidance.
namespace DDCUI
{
partial class PointCtrlForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.CmbSubDevice = new System.Windows.Forms.ComboBox();
this.BtnBack = new System.Windows.Forms.Button();
this.CmbMainDevice = new System.Windows.Forms.ComboBox();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.BtnRefresh = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.PointName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Value = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Description = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.DefaultValue = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ActiveString = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.InactiveString = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.AlarmCondition = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 6;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 151F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 88F));
this.tableLayoutPanel1.Controls.Add(this.CmbSubDevice, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.BtnBack, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.CmbMainDevice, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.dataGridView1, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.BtnRefresh, 4, 1);
this.tableLayoutPanel1.Controls.Add(this.label1, 5, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 3;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 67.02128F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 32.97872F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 368F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(639, 467);
this.tableLayoutPanel1.TabIndex = 0;
//
// CmbSubDevice
//
this.tableLayoutPanel1.SetColumnSpan(this.CmbSubDevice, 2);
this.CmbSubDevice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CmbSubDevice.Font = new System.Drawing.Font("굴림", 12F);
this.CmbSubDevice.FormattingEnabled = true;
this.CmbSubDevice.Location = new System.Drawing.Point(203, 69);
this.CmbSubDevice.Name = "CmbSubDevice";
this.CmbSubDevice.Size = new System.Drawing.Size(194, 24);
this.CmbSubDevice.TabIndex = 3;
//
// BtnBack
//
this.BtnBack.Location = new System.Drawing.Point(3, 3);
this.BtnBack.Name = "BtnBack";
this.BtnBack.Size = new System.Drawing.Size(94, 54);
this.BtnBack.TabIndex = 0;
this.BtnBack.Text = "Back";
this.BtnBack.UseVisualStyleBackColor = true;
this.BtnBack.Click += new System.EventHandler(this.BtnBack_Click);
//
// CmbMainDevice
//
this.tableLayoutPanel1.SetColumnSpan(this.CmbMainDevice, 2);
this.CmbMainDevice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CmbMainDevice.Font = new System.Drawing.Font("굴림", 12F);
this.CmbMainDevice.FormattingEnabled = true;
this.CmbMainDevice.Items.AddRange(new object[] {
"I/O",
"VIRTUAL",
"SAC",
"MODBUS",
"NATIONAL",
"TOSHIBA",
"SCHEDULE",
"SYSTEM ALARM",
"LOGIC",
"GROUP"});
this.CmbMainDevice.Location = new System.Drawing.Point(3, 69);
this.CmbMainDevice.Name = "CmbMainDevice";
this.CmbMainDevice.Size = new System.Drawing.Size(194, 24);
this.CmbMainDevice.TabIndex = 2;
this.CmbMainDevice.SelectedIndexChanged += new System.EventHandler(this.CmbMainDevice_SelectedIndexChanged);
//
// dataGridView1
//
this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.PointName,
this.Value,
this.Description,
this.DefaultValue,
this.ActiveString,
this.InactiveString,
this.AlarmCondition});
this.tableLayoutPanel1.SetColumnSpan(this.dataGridView1, 6);
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point(3, 101);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(633, 363);
this.dataGridView1.TabIndex = 5;
//
// BtnRefresh
//
this.BtnRefresh.Location = new System.Drawing.Point(403, 69);
this.BtnRefresh.Name = "BtnRefresh";
this.BtnRefresh.Size = new System.Drawing.Size(94, 26);
this.BtnRefresh.TabIndex = 6;
this.BtnRefresh.Text = "Refresh";
this.BtnRefresh.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.label1.Font = new System.Drawing.Font("굴림", 12F);
this.label1.Location = new System.Drawing.Point(554, 66);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(82, 32);
this.label1.TabIndex = 7;
this.label1.Text = "XXX 개";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ID
//
this.ID.FillWeight = 70F;
this.ID.HeaderText = "ID";
this.ID.Name = "ID";
//
// PointName
//
this.PointName.FillWeight = 70F;
this.PointName.HeaderText = "이름";
this.PointName.Name = "PointName";
//
// Value
//
this.Value.FillWeight = 70F;
this.Value.HeaderText = "값";
this.Value.Name = "Value";
//
// Description
//
this.Description.FillWeight = 70F;
this.Description.HeaderText = "설명";
this.Description.Name = "Description";
//
// DefaultValue
//
this.DefaultValue.FillWeight = 70F;
this.DefaultValue.HeaderText = "초기값";
this.DefaultValue.Name = "DefaultValue";
//
// ActiveString
//
this.ActiveString.HeaderText = "Active문자열";
this.ActiveString.Name = "ActiveString";
//
// InactiveString
//
this.InactiveString.HeaderText = "InActive문자열";
this.InactiveString.Name = "InactiveString";
//
// AlarmCondition
//
this.AlarmCondition.HeaderText = "알람조건";
this.AlarmCondition.Name = "AlarmCondition";
//
// PointCtrlForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(639, 467);
this.Controls.Add(this.tableLayoutPanel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "PointCtrlForm";
this.Text = "LG-DDC";
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button BtnBack;
private System.Windows.Forms.ComboBox CmbMainDevice;
private System.Windows.Forms.ComboBox CmbSubDevice;
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.Button BtnRefresh;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.DataGridViewTextBoxColumn ID;
private System.Windows.Forms.DataGridViewTextBoxColumn PointName;
private System.Windows.Forms.DataGridViewTextBoxColumn Value;
private System.Windows.Forms.DataGridViewTextBoxColumn Description;
private System.Windows.Forms.DataGridViewTextBoxColumn DefaultValue;
private System.Windows.Forms.DataGridViewTextBoxColumn ActiveString;
private System.Windows.Forms.DataGridViewTextBoxColumn InactiveString;
private System.Windows.Forms.DataGridViewTextBoxColumn AlarmCondition;
}
}
I've found the solution and it's rather simple.
The row and column sizes for the DGV has to be set "percentage (relative)" not "absolute" in order for the docking to work properly.
You can edit the sizes by right clicking on one of the cells of the DGV and clicking on Edit Row/Column Properties.

resizing in the FlowLayoutPanel

hii
I am having a form in which there is one datagridview which is in the flowlayoutpanel and there is other controls such as button an text box at the bottom
I need to resize the datagrid view when the form is resized.but it shud not fill the entire form because the button and text box should not be get affected.but i need the datagrid to fill the maximum part of the screen leaving space for text box and button at the bottom..help me plz...
I think you don't need the FlowLayoutPanel for this purpose. Just try this code in your Designer.cs and tell me if this looks the way you like.
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.panel1 = new System.Windows.Forms.Panel();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point(0, 0);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(520, 406);
this.dataGridView1.TabIndex = 0;
//
// panel1
//
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.textBox1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel1.Location = new System.Drawing.Point(0, 376);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(520, 30);
this.panel1.TabIndex = 1;
//
// textBox1
//
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox1.Location = new System.Drawing.Point(3, 5);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(433, 20);
this.textBox1.TabIndex = 0;
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(442, 4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// FormMain
//
this.ClientSize = new System.Drawing.Size(520, 406);
this.Controls.Add(this.panel1);
this.Controls.Add(this.dataGridView1);
this.Name = "FormMain";
this.Text = "FormMain";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;

Categories