我在開發WindowsFormApplication,其中一個主窗體存在幾個子窗體。 我的一個表單生成報告,之後我想通過關閉作爲報告生成一部分調用的所有其他中間表單來調用父窗體。當用戶嘗試使用常用關閉按鈕「X」(用於關閉Windows操作系統中的公共窗口的按鈕)關閉報告時,我想調用父窗口。報告生成後調用父窗口
如何隨時從我的任何子窗體訪問我的父窗體/ startupform? 當Last form終止時,如何關閉除主窗體之外的所有其他子窗體?
有人請幫助我.. 在此先感謝..
我在開發WindowsFormApplication,其中一個主窗體存在幾個子窗體。 我的一個表單生成報告,之後我想通過關閉作爲報告生成一部分調用的所有其他中間表單來調用父窗體。當用戶嘗試使用常用關閉按鈕「X」(用於關閉Windows操作系統中的公共窗口的按鈕)關閉報告時,我想調用父窗口。報告生成後調用父窗口
如何隨時從我的任何子窗體訪問我的父窗體/ startupform? 當Last form終止時,如何關閉除主窗體之外的所有其他子窗體?
有人請幫助我.. 在此先感謝..
在WinForms應用程序的應用對象有一個OpenForms集合,其中包含所有打開的表單的引用。您可以從該集合中獲取表單的引用,並在其上調用Close()來關閉它。
而且您的意見,在finalreport的OnClosing事件中,你可以運行此代碼
foreach (Form f in Application.OpenForms)
{
if (f.GetType().ToString().Contains("start"))
f.Focus();
}
要關閉您的最終形式,當顯示啓動窗體,您可以添加事件處理程序,最終的事件FormClosed
形式是這樣的:
FinalForm f = new FinalForm();
f.FormClosed += (s,e) => {
StartupForm sf = new StartupForm();
sf.Show;
//if your StartupForm is defined somewhere
//just call sf.Show();
};
//If you are using VS 2005 or below, you have to define a method for FormClosed event handler (unable to use the lambda expression above
private void FormClosedHandler(object sender, FormClosedEventArgs e){
StartupForm sf = new StartupForm();
sf.Show;
//if your StartupForm is defined somewhere
//just call sf.Show();
}
//Register the FormClosed event with the event handler above
f.FormClosed += new FormClosedEventHandler(FormClosedHandler);
//show your final form
f.Show();
//if this form is closed, the event FormClosed will be raised and the corresponding event handler (we added above) will be called.
你如何顯示你的'最終報告'表單?我想知道你如何組織你的表格。例如,我通常在我的主表單的類中定義了我的子/子表單成員。所以我可以很容易地在主窗體中顯示任何子/子窗體。 –
我創建了每個表單,並在需要時通過在特定表單上創建一個對象來調用它們,如下所示:在第一個表單中.. secondform fr = new secondform(); fr.show(); – rtvalluri