2014-03-13 96 views
-1

我必須固定在UI文本框是永遠不會分配給,永遠有它的默認值空

UI

一些事情

在應用程序運行完全正常 但是,當我改變的大小groupboxsize,它給我一個錯誤。

  1. 變量'txtHeureMinutes'要麼是未聲明的,要麼從未分配過 。
  2. 變量「txtHeureHeure」要麼是未申報或者被 從未分配

下面是一個代碼

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

+0

問題是? – Max

+1

我想這不是一個錯誤。這只是一個'警告'。 –

+0

@MaxMommersteeg:我想現在你可以回答我的問題 – GameBuilder

回答

1

您可能要檢查designer.cs文件,以確認文本框確實存在於表單控件的集合中。

+0

沒有要求在任何訪問這些字段的*方法*之前聲明* fields *。 –

+0

是這樣嗎?我沒有意識到這一點。我會編輯我的答案。 –

+0

@ shree.pat18:是的,它存在我添加了一些圖像。 – GameBuilder

相關問題