C#:属性中的大小与代码不同

C#:属性中的大小与代码不同,c#,windows-forms-designer,C#,Windows Forms Designer,我在属性中为标签的大小设置(100100),在代码中为另一个标签设置(100100) 但是大小不同。(代码标签比其他标签大) 也取决于我的代码,这两个标签最粘在一起。但结果是不同的 这是我的Form1.cs: using System; using System.Drawing; using System.Windows.Forms; namespace BBSquare { public partial class Form1 : Form { public

我在属性中为标签的大小设置(100100),在代码中为另一个标签设置(100100)

但是大小不同。(代码标签比其他标签大)
也取决于我的代码,这两个标签最粘在一起。但结果是不同的

这是我的Form1.cs:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace BBSquare
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Label cell = new Label();
            cell.Size = new Size(100, 100);
            cell.Location = new Point(100, 0);
            cell.BackColor = Color.Blue;

            panel.Controls.Add(cell);
        }
    }
}
这是我得到的结果: (左侧标签具有(100100)大小和(0,0)位置)

**编辑:这是我的Form1.Designer.cs**

namespace BBSquare
{
    partial class Form1
    {
        /// <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.panel = new System.Windows.Forms.Panel();
            this.label1 = new System.Windows.Forms.Label();
            this.panel.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel
            // 
            this.panel.BackColor = System.Drawing.SystemColors.ActiveCaption;
            this.panel.Controls.Add(this.label1);
            this.panel.Location = new System.Drawing.Point(100, 141);
            this.panel.Name = "panel";
            this.panel.Size = new System.Drawing.Size(600, 600);
            this.panel.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.BackColor = System.Drawing.Color.Green;
            this.label1.BorderStyle = 
System.Windows.Forms.BorderStyle.FixedSingle;
            this.label1.Location = new System.Drawing.Point(0, 0);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(100, 100);
            this.label1.TabIndex = 0;
            this.label1.Text = "label1";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.Red;
            this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.ClientSize = new System.Drawing.Size(782, 753);
            this.Controls.Add(this.panel);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.panel.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Panel panel;
        private System.Windows.Forms.Label label1;
    }
}
命名空间BBSquare
{
部分类Form1
{
/// 
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()
{
this.panel=new System.Windows.Forms.panel();
this.label1=new System.Windows.Forms.Label();
this.panel.SuspendLayout();
这个.SuspendLayout();
// 
//面板
// 
this.panel.BackColor=System.Drawing.SystemColors.ActiveCaption;
this.panel.Controls.Add(this.label1);
this.panel.Location=新系统图纸点(100141);
this.panel.Name=“panel”;
this.panel.Size=新系统图纸尺寸(600600);
this.panel.TabIndex=0;
// 
//标签1
// 
this.label1.BackColor=System.Drawing.Color.Green;
this.label1.BorderStyle=
System.Windows.Forms.BorderStyle.FixedSingle;
this.label1.Location=新系统图点(0,0);
this.label1.Name=“label1”;
this.label1.Size=新系统图纸尺寸(100100);
this.label1.TabIndex=0;
this.label1.Text=“label1”;
// 
//表格1
// 
此.AutoScaleDimensions=新系统.Drawing.SizeF(8F,16F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.BackColor=System.Drawing.Color.Red;
this.BackgroundImageLayout=System.Windows.Forms.ImageLayout.None;
this.ClientSize=新系统图尺寸(782753);
this.Controls.Add(this.panel);
this.Name=“Form1”;
this.Text=“Form1”;
this.Load+=new System.EventHandler(this.Form1\u Load);
此.panel.resume布局(false);
此选项为.resume布局(false);
}
#端区
private System.Windows.Forms.Panel面板;
private System.Windows.Forms.label1;
}
}

您的位置属性无效。在设计器中:

// 
// Form1
// 
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); <--
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; <--
...
this.panel.ResumeLayout(false);
this.ResumeLayout(false);
//
//表格1
// 

此.AutoScaleDimensions=新系统.Drawing.SizeF(8F,16F);它在某个地方被覆盖了…我们不知道在哪里-我们不拥有所有的代码。@Reniuz这是我的完整代码。此代码的形式为加载
(左侧标签具有(100100)大小和(0,0)位置)
如果右侧标签具有
单元格,则不能为真。大小=新大小(100100);单元位置=新点(100,0)。如果这是真的,则块将重叠(或至少彼此“接触”)。这意味着,正如Reniuz所说,您的代码中正在发生其他事情。您可以发布表单设计器生成的代码吗?
并在我的代码中为另一个标签设置(100100)代码在哪里?您的代码设置为红色-图片中没有红色标签。请添加您的实际代码,以便我们可以复制该问题。@hamed我们需要更多代码。发布设计器代码,在解决方案资源管理器中,单击表单条目旁边的扩展程序“+”并显示.designer.cs