2014-03-25 22 views

回答

0

在您的目標Winform類中創建一個新的構造函數,該值將該值作爲參數。爲後續表單做同樣的事情。

private MyType _value; 

public MyForm(MyType myValue) : this() 
{ 
    _value = myValue; 
} 

要從原來的形式顯示新的形式:

var form = new MyForm(someValue); 
form.Show(); // or ShowDialog() 
+0

感謝您的回覆。我有3個表格,如何在第三個表格上進行訪問? – user3461835

+0

完全是我描述它的方式。 –

+0

這可以在一個表單上做兩次嗎? – user3461835

0

使用get /集來定義你的價值:

Class Form1 
int _x; // value you want to access from other class/form 
public int YourNumber; 
{ 
    get 
    { 
    return this._x; 
    } 
    set 
    { 
    this._x= value; 
    } 
} 

現在訪問/從其他類,例如修改Form2:

Class Form2 
Form1 form = new Form1(); 
form.YourNumber = 5; // and it's changed in Form1 also 

int y = form.YourNumber; // and you get it from Form1