C# Visual Studio在我运行程序时移动标签

C# Visual Studio在我运行程序时移动标签,c#,winforms,visual-studio,C#,Winforms,Visual Studio,我的窗口设计看起来很好,我希望它看起来如何,但一旦我运行我的程序,标签会随着按钮一起移动和调整大小。这也发生在我的另一个窗口很好。我在Windows 10上运行,也在使用Visual Studio 2017 下面是我的设计窗口的外观 下面是我执行程序后的外观 这是我的InitializeComponent函数: private void InitializeComponent() { System.ComponentModel.ComponentResourc

我的窗口设计看起来很好,我希望它看起来如何,但一旦我运行我的程序,标签会随着按钮一起移动和调整大小。这也发生在我的另一个窗口很好。我在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();

    }

谢谢。

这似乎是由于windows样式造成的。您只需要使用您的设计来确保事物的大小、对齐、间隔、锚定等。。。根据用户可能使用的不同样式,确保事情看起来合理正确。没有真正的“魔弹”,你只需要使用你的格式。您也可以使用TableLayoutPanel来提供一些帮助。它还可以帮助一些人将表单的整体尺寸放大一点,将元素隔开一点,并将按钮放大一点

此外,还有一些进一步的建议/想法:


您从资源中提取一些文本有什么原因吗?如果您从某处提取可变数据,那么最终肯定会得到不可预测的布局。如果这是您所需要的,那么您将需要动态地格式化您的布局,以考虑到这一点,但这似乎是不必要的


此外,我认为没有理由列出文本中可用的功能,因为这些功能已在按钮下面列出。您甚至可以去掉所有这些按钮,将您的选择放入一个下拉列表中,只需一个按钮即可激活所选项目。

这似乎是由于windows样式所致。您只需要使用您的设计来确保事物的大小、对齐、间隔、锚定等。。。根据用户可能使用的不同样式,确保事情看起来合理正确。没有真正的“魔弹”,你只需要使用你的格式。您也可以使用
TableLayoutPanel
来提供一些帮助。此外,您还可以在问题中添加
InitializeComponent
函数中的代码,并将其包含在表单设计器代码文档中。通过这种方式,我们可以了解您是如何设置控件的。首先检查您使用的字体。其次,查看这些组件的大小,并确保文本是否适合。第三,看看这些组件的锚定,最后一个,你一定要改变形状的大小,因为在制作这么小的组件时,设计本身总是有一些不规则的地方。如果你想使用这种大小的表单,你应该使用VS Blend来处理设计。我理解这一点,但是每当你创建这样的表单时,它仍然会生成设计器代码。这就是布局的处理方式。它可能看起来很直观,但仍然只是表单设计器代码文件(
Form1.Designer.cs
)中的代码。打开该文件,复制
InitializeComponent
函数并将其添加到问题中。其中包含所有表单元素设置。是否有从资源中提取部分文本的原因?如果您从某处提取可变数据,那么最终肯定会得到不可预测的布局。如果这是您所需要的,那么您将需要动态地格式化您的布局,以考虑到这一点,但这似乎是不必要的。而且,我看不出有什么理由列出哪些功能是可用的,因为它们已经用按钮列出了。您甚至可以去掉所有这些按钮,并将您的选择放在一个下拉列表中,只需一个按钮即可激活所选项目。