如果您需要無模式表單中的數據,則應使用事件或其他通知模式。
class OkPressedEventArgs : EventArgs
{
public OkPressedEventArgs(string text1, string text2, string text3)
{
Text1 = text1;
Text2 = text2;
Text3 = text3;
}
public string Text1 {get;private set;}
public string Text2 {get;private set;}
public string Text3 {get;private set;}
}
class SourceForm : Form
{
public event EventHandler<OkPressedEventArgs> OkPressed;
private void OnOkPressed()
{
if(OkPressed != null)
{
OkPressed(this, new OkPressedEventArgs(textBox1.Text, textBox2.Text, textBox2.Text);
}
}
private void okButton_Click(object source, EventArgs e)
{
OnOkPressed();
}
}
class TargetClass
{
void ShowFormMethod()
{
var form = new SourceForm();
form.OkPressed += OkPressedHandler;
form.Show();
}
private void OkPressedHandler(object source, OkPressedEventArgs e)
{
// process form data here!
}
}
Ok按鈕是否會關閉窗體? – 2011-05-13 09:05:06
我認爲是的,它會做:this.Close(),但我不能調用onClose事件? – 2011-05-13 09:16:11
你需要模態對話框嗎?這意味着調用代碼將等待顯示錶單關閉。 – 2011-05-13 09:27:41