Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 类型';System.Windows.Forms.Form';没有名为'的属性;textBox1';_C#_Visual Studio 2013_Properties_Windows Forms Designer - Fatal编程技术网

C# 类型';System.Windows.Forms.Form';没有名为'的属性;textBox1';

C# 类型';System.Windows.Forms.Form';没有名为'的属性;textBox1';,c#,visual-studio-2013,properties,windows-forms-designer,C#,Visual Studio 2013,Properties,Windows Forms Designer,正如人们在评论中指出的那样,对于真正的应用程序,您永远不应该这样做,因为这是一种糟糕的做法。我只是想了解属性在VisualStudio中是如何工作的,在真正的应用程序中永远不会这样做 每当我试图查看我创建的表单的设计时,就会出现此错误。我深入代码,将textBox1字段设置为public,并添加了getter和setter: namespace WindowsFormsApplication2 { partial class Form2 { /// <sum

正如人们在评论中指出的那样,对于真正的应用程序,您永远不应该这样做,因为这是一种糟糕的做法。我只是想了解属性在VisualStudio中是如何工作的,在真正的应用程序中永远不会这样做

每当我试图查看我创建的表单的设计时,就会出现此错误。我深入代码,将textBox1字段设置为public,并添加了getter和setter:

namespace WindowsFormsApplication2
{
    partial class Form2
    {
        /// <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.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(85, 82);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 20);
            this.textBox1.TabIndex = 0;
            // 
            // Form2
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 261);
            this.Controls.Add(this.textBox1);
            this.Name = "Form2";
            this.Text = "Form2";
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        #endregion
        public System.Windows.Forms.TextBox textBox1 { get; private set; }
    }
}
命名空间窗口窗体应用程序2
{
部分类别表格2
{
/// 
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()
{
this.textBox1=new System.Windows.Forms.TextBox();
这个.SuspendLayout();
// 
//文本框1
// 
this.textBox1.Location=新系统.图纸.点(85,82);
this.textBox1.Name=“textBox1”;
this.textBox1.Size=新系统.Drawing.Size(100,20);
this.textBox1.TabIndex=0;
// 
//表格2
// 
此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=新系统.Drawing.Size(284261);
this.Controls.Add(this.textBox1);
this.Name=“Form2”;
this.Text=“Form2”;
此选项为.resume布局(false);
这个。执行布局();
}
#端区
public System.Windows.Forms.TextBox textBox1{get;private set;}
}
}
当我运行该程序时,它编译并运行时没有错误,而且显然声明了textBox1属性。当我使用属性而不是普通字段时,为什么Visual Studio会中断


编辑:感谢您修复了代码块,我本来打算自己修复的

您会遇到此错误,因为您正在手动更改设计器生成的代码。
如果单击设计器中的文本框,则可以通过设计器本身将其公开,这样就不会出现此问题。

与其将字段替换为公共自动属性,不如添加一个属性来访问设计器生成的字段?您真的不应该尝试更改designer.cs文件。。使用该部分的另一半class@GrawCube,我认为使用auto属性比为每个组件使用单独的属性要简单。理论上,这应该是可行的。我只是想知道为什么没有。赛斯我知道,但这更像是一个实验。如果我在写一个实际的应用程序,我永远不会这么做。我能把它变成一个财产吗?我试图让它可以从类外访问,但仍然保持对字段设置的控制(并且不使用Java风格的getter/accessor)。但不要在设计器生成的文件中执行此操作。在设计器中的窗体上单击鼠标右键,然后选择“查看代码”。在那里,您可以创建编辑框的属性。