2016-10-17 2 views
2

을 닫습니다 : 나는 두 번째 양식을 닫을 때 내가 처음에 이벤트를 트리거하려면 지금통화 이벤트 두 번째 형태는, 내가 열고이 같은 두 번째 양식 ShowDialog를 내가 두 가지 형태가

Recieving_Stock_Form f = new Recieving_Stock_Form(); 
f.Username = Username; 
f.Role = Role; 
f.Date = monthCalendar1.SelectionStart.ToString(@"yyyy\/MM\/dd"); 
f.ShowDialog(); 

을 형태 EG

void txtStockCount_TextChanged(object sender, EventArgs e) 

나는이 나 어떻게 할 방법에 대해 찾아 볼 수 있습니다 어떤 아이디어가?

감사

답변

1

ShowDialog은 그래서 executiong을 차단 모달, 그래서 당신이 그것을 닫을 때, 다음 일이 실행됩니다.

당신은이 작업을 수행 할 수 있습니다

Recieving_Stock_Form f = new Recieving_Stock_Form(); 
f.Username = Username; 
f.Role = Role; 
f.Date = monthCalendar1.SelectionStart.ToString(@"yyyy\/MM\/dd"); 
f.ShowDialog(); 
// it will continue here when the form is closed. 
txtStockCount_TextChanged(this, EventArgs.Empty); // or assign the variable directly. 
+2

이 가장 빠르고 간단한 대답이다. 고맙습니다. – Cleaven

4

Form1에, 코드가이

Recieving_Stock_Form f = new Recieving_Stock_Form(); 

당신은 코드

f.Form_Closing += ExampleHandler; 

ExampleHandler(object sender, FormClosingEventArgs e) 
{ 
    //Do stuff 
} 
+1

모달 양식에 'closing' 이벤트를 등록하는 이유는 무엇입니까? –

+0

두 번째 형식과 반대되는 첫 번째 형식으로 실행되기 때문에 –

+0

하지만 'ShowDialog'은 모달이며 닫히기 전까지 실행을 차단합니다. 따라서 언제 폐쇄되어 있는지 항상 알 수 있습니다. –

2

이를 추가 할 수 있다고 가정하는 것은 두 가지 이벤트입니다 당신 귀하의 결정에 따라 FormClosedFormClosing을 처리 할 수 ​​있습니다. 엔.

f.FormClosed += f_FormClosed; 

private void f_FormClosed(object sender, FormClosedEventArgs e) 
{ 
    //Call your function or do whatever you want 
} 
+0

도와 줘서 고맙습니다. – Cleaven

+1

당신을 환영합니다! – SeM

2

나는 형식에 속아 넘어 가지 않았 으면 좋겠다. 대신에, 나는 txtStockCountRecieving_Stock_Form의 값을 할당하는 것이 좋습니다 :

using (Recieving_Stock_Form f = new Recieving_Stock_Form()) { 
    f.Username = Username; 
    f.Role = Role; 
    f.Date = monthCalendar1.SelectionStart.ToString(@"yyyy\/MM\/dd"); 

    // == DialogResult.OK - let user have a chance to cancel his/her input 
    if (f.ShowDialog() == DialogResult.OK) { 
    //TODO: put the right property here 
    txtStockCount.Text = f.StockCount.ToString(); 
    } 
} 
+0

도움 주셔서 감사합니다 :) – Cleaven

관련 문제