如何將孩子的值傳遞回父表單?如何將孩子的值傳遞回父表單?我有一個字符串,我想傳遞給父母。我使用以下方式啟動了孩子FormOptions formOptions = new FormOptions();formOptions.ShowDialog();
3 回答
繁星coding
TA貢獻1797條經驗 獲得超4個贊
創建一個屬性(或方法)FormOptions,比如說GetMyResult:
using (FormOptions formOptions = new FormOptions()){
formOptions.ShowDialog();
string result = formOptions.GetMyResult;
// do what ever with result...}
慕雪6442864
TA貢獻1812條經驗 獲得超5個贊
您還可以創建公共屬性。
// Using and namespace...
public partial class FormOptions : Form
{
private string _MyString; // Use this
public string MyString { // in
get { return _MyString; } // .NET
} // 2.0
public string MyString { get; } // In .NET 3.0 or newer
// The rest of the form code
}
然后你可以得到它:
FormOptions formOptions = new FormOptions();
formOptions.ShowDialog();
string myString = formOptions.MyString;
- 3 回答
- 0 關注
- 367 瀏覽
添加回答
舉報
0/150
提交
取消
