我的窗口设计看起来很好,我希望它看起来如何,但是,一旦我运行程序,标签就会移动并随按钮一起调整大小。这也发生在我的其他窗口很好。我在Windows 10上运行,我也在使用Visual Studio 2017。
以下是我的设计窗口假设的样子
这是我执行程序后的外观
这是我的InitializeComponent
功能:
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.welcomeLabel = new System.Windows.Forms.Label();
this.contactDeveloperLabel = new System.Windows.Forms.Label();
this.addProductsButton = new System.Windows.Forms.Button();
this.viewProductsButton = new System.Windows.Forms.Button();
this.addSuppliersButton = new System.Windows.Forms.Button();
this.deleteProductsButton = new System.Windows.Forms.Button();
this.editProductsButton = new System.Windows.Forms.Button();
this.quickEditButton = new System.Windows.Forms.Button();
this.contactDeveloper = new System.Windows.Forms.Button();
this.shopStockLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// welcomeLabel
//
this.welcomeLabel.Location = new System.Drawing.Point(21, 51);
this.welcomeLabel.Name = "welcomeLabel";
this.welcomeLabel.Size = new System.Drawing.Size(297, 120);
this.welcomeLabel.TabIndex = 2;
this.welcomeLabel.Text = resources.GetString("welcomeLabel.Text");
this.welcomeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// contactDeveloperLabel
//
this.contactDeveloperLabel.Location = new System.Drawing.Point(36, 241);
this.contactDeveloperLabel.Name = "contactDeveloperLabel";
this.contactDeveloperLabel.Size = new System.Drawing.Size(268, 40);
this.contactDeveloperLabel.TabIndex = 3;
this.contactDeveloperLabel.Text = "If any problem occurs please contact\r\nthe developer immediately ";
this.contactDeveloperLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// addProductsButton
//
this.addProductsButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.addProductsButton.Location = new System.Drawing.Point(21, 178);
this.addProductsButton.Name = "addProductsButton";
this.addProductsButton.Size = new System.Drawing.Size(93, 28);
this.addProductsButton.TabIndex = 4;
this.addProductsButton.Text = "Add Products";
this.addProductsButton.UseVisualStyleBackColor = true;
this.addProductsButton.Click += new System.EventHandler(this.addProductsButton_Click);
//
// viewProductsButton
//
this.viewProductsButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.viewProductsButton.Location = new System.Drawing.Point(224, 178);
this.viewProductsButton.Name = "viewProductsButton";
this.viewProductsButton.Size = new System.Drawing.Size(93, 28);
this.viewProductsButton.TabIndex = 5;
this.viewProductsButton.Text = "View Products";
this.viewProductsButton.UseVisualStyleBackColor = true;
//
// addSuppliersButton
//
this.addSuppliersButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.addSuppliersButton.Location = new System.Drawing.Point(122, 178);
this.addSuppliersButton.Name = "addSuppliersButton";
this.addSuppliersButton.Size = new System.Drawing.Size(93, 28);
this.addSuppliersButton.TabIndex = 6;
this.addSuppliersButton.Text = "Add Suppliers";
this.addSuppliersButton.UseVisualStyleBackColor = true;
//
// deleteProductsButton
//
this.deleteProductsButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.deleteProductsButton.Location = new System.Drawing.Point(21, 212);
this.deleteProductsButton.Name = "deleteProductsButton";
this.deleteProductsButton.Size = new System.Drawing.Size(93, 28);
this.deleteProductsButton.TabIndex = 7;
this.deleteProductsButton.Text = "Delete Products";
this.deleteProductsButton.UseVisualStyleBackColor = true;
//
// editProductsButton
//
this.editProductsButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.editProductsButton.Location = new System.Drawing.Point(122, 212);
this.editProductsButton.Name = "editProductsButton";
this.editProductsButton.Size = new System.Drawing.Size(93, 28);
this.editProductsButton.TabIndex = 8;
this.editProductsButton.Text = "Edit Products";
this.editProductsButton.UseVisualStyleBackColor = true;
//
// quickEditButton
//
this.quickEditButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.quickEditButton.Location = new System.Drawing.Point(224, 212);
this.quickEditButton.Name = "quickEditButton";
this.quickEditButton.Size = new System.Drawing.Size(93, 28);
this.quickEditButton.TabIndex = 9;
this.quickEditButton.Text = "Quick Edit";
this.quickEditButton.UseVisualStyleBackColor = true;
//
// contactDeveloper
//
this.contactDeveloper.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.contactDeveloper.Location = new System.Drawing.Point(115, 283);
this.contactDeveloper.Name = "contactDeveloper";
this.contactDeveloper.Size = new System.Drawing.Size(110, 28);
this.contactDeveloper.TabIndex = 10;
this.contactDeveloper.Text = "Contact Developer";
this.contactDeveloper.UseVisualStyleBackColor = true;
//
// shopStockLabel
//
this.shopStockLabel.AutoSize = true;
this.shopStockLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.shopStockLabel.Location = new System.Drawing.Point(66, 10);
this.shopStockLabel.Name = "shopStockLabel";
this.shopStockLabel.Size = new System.Drawing.Size(204, 39);
this.shopStockLabel.TabIndex = 11;
this.shopStockLabel.Text = "Shop Stock";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange;
this.BackColor = System.Drawing.Color.Silver;
this.ClientSize = new System.Drawing.Size(339, 323);
this.Controls.Add(this.shopStockLabel);
this.Controls.Add(this.contactDeveloper);
this.Controls.Add(this.quickEditButton);
this.Controls.Add(this.editProductsButton);
this.Controls.Add(this.deleteProductsButton);
this.Controls.Add(this.addSuppliersButton);
this.Controls.Add(this.viewProductsButton);
this.Controls.Add(this.addProductsButton);
this.Controls.Add(this.contactDeveloperLabel);
this.Controls.Add(this.welcomeLabel);
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.Name = "Form1";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
谢谢。
答案 0 :(得分:0)
这似乎是由于Windows样式。您只需要与您的设计一起工作,以确保尺寸,对齐,间隔,固定等等,以确保根据用户可能使用的不同样式合理地看起来正确。没有真正的“魔术子弹”,你只需要玩你的格式。您也可以使用TableLayoutPanel来帮助一点。它也可能有助于一些人使表单的整体大小更大一些,并使你的元素更多,并使按钮更大。
另外,作为一些进一步的建议/想法:
您是否有理由从资源中提取部分文字?如果你从某个地方提取可变数据,你肯定会得到一个不可预测的布局。如果这就是您所需要的,那么您将需要动态格式化您的布局以将其考虑在内,但这看起来似乎没有必要。
此外,我认为没有理由列出文本中可用的功能,当它们已经在按钮下方列出时。您甚至可以摆脱所有这些按钮,并将您的选择放在一个下拉列表中,只需一个按钮即可激活所选项目。