永远不会将文本框分配给,并始终将其默认值设置为null

时间:2014-03-13 10:35:58

标签: c# winforms debugging

我必须在UI上修复一些东西

UI

应用程序运行正常 但是当我改变groupboxsize的大小时,它会给我一个错误。

  1. 变量'txtHeureMinutes'要么未声明,要么永远不会 分配。
  2. 变量'txtHeureHeure'要么是未声明的,要么是未声明的 从未分配
  3. 这是一个代码

    public class NumericalTextBox : TextBox
    {
        private int MaxValue;
    
        public NumericalTextBox(int max_value = -1)
        {
            MaxValue = max_value;
        }
    
        protected override void OnKeyDown(KeyEventArgs e)
        {
    
        }
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
    
        }
    
    }
    
    partial class TestClass
    {
        // some code
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();        
    
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.txtHeureMinutes = new MyComp.Common.Controls.NumericalTextBox(60);
            this.txtHeureHeure = new MyComp.Common.Controls.NumericalTextBox(24);
    
            this.splitContainer1.Panel2.Controls.Add(this.groupBox1);
    
            this.groupBox1.Controls.Add(this.txtHeureMinutes);
            this.groupBox1.Controls.Add(this.txtHeureHeure);
            this.groupBox1.Size = new System.Drawing.Size(270, 270);
        }
    
        // declaration
        private MyComp.Common.Controls.NumericalTextBox txtHeureMinutes;
        private MyComp.Common.Controls.NumericalTextBox txtHeureHeure;
    }
    

    enter image description here

1 个答案:

答案 0 :(得分:1)

您可能需要检查designer.cs文件以确认文本框确实存在于表单控件集合中。