【发布时间】:2017-10-05 15:54:07
【问题描述】:
我有以下基本的 WinForm:
将表单缩放到比此设计器视图更大的尺寸后,所有控件都可以很好地适应父容器的新高度/宽度要求。 表单控件的所有停靠属性都设置为 Fill 每个父容器。但是,当窗体的大小调整为小于“设计器”视图时,控件的大小不会正确调整。见下文:
我检查了所有控件的 MinimumSize 属性,这似乎不是问题。设计师代码:
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);
}
有什么想法吗?
【问题讨论】:
-
检查 GroupBoxes 和所有父容器。
-
@LarsTech 具体是为了什么? Dock = 填充?
-
与流行的看法相反,Winforms 表单的工作方式是由代码控制的,而不是由像素控制的。发布像素并不能帮助我们帮助您找到代码中的问题。
-
我现在只是在看动画。上下调整大小看起来不像正确缩放。但是我们没有代码可以看,所以谁知道呢。
-
@HansPassant 公平点。添加了设计器代码。