我有用c#編寫的Windows窗體應用程序。當有人按下「清除」按鈕時,我想重新加載表單。但我無法實現呼叫負載事件。這些線路也沒有工作:重新加載Windows窗體而不關閉並重新打開
this.Refresh();
this.Load +=new EventHandler(Grafik_Load); // 'Grafik' is the name of the form.
我應該怎麼做呢?感謝您的幫助..
我有用c#編寫的Windows窗體應用程序。當有人按下「清除」按鈕時,我想重新加載表單。但我無法實現呼叫負載事件。這些線路也沒有工作:重新加載Windows窗體而不關閉並重新打開
this.Refresh();
this.Load +=new EventHandler(Grafik_Load); // 'Grafik' is the name of the form.
我應該怎麼做呢?感謝您的幫助..
將「加載」代碼放在一個單獨的函數中,並從您自己的代碼/加載事件處理函數中調用該函數。
其實我已經有喜歡的負載功能: 私人無效Grafik_Load(對象發件人,EventArgs的){ .... } 但 我沒有找到正確的語法來調用它 – user741319
Grafik_Load(NULL,NULL ) 應該管用。 – CodingBarfield
我發現hide/show,show部分創建了同一個窗體的另一個實例,所以我最好放置當前窗體,創建它的一個新實例並顯示它。
Grafik objFrmGrafik = new Grafik();
this.Dispose();
objFrmGrafik .Show();
首頁爲MDI格式名稱。我已經測試過它。
home.ActiveForm.Dispose();
home sd = new home();
sd.Show();
private void callonload()
{
//code which u wrriten on load event
}
private void Form_Load(object sender, EventArgs e)
{
callonload();
}
private void btn_clear_Click(object sender, EventArgs e)
{
callonload();
}
//it is a good idea to use the 'sender' object when calling the form load method
//because doing so will let you determine if the sender was a button click or something else...
private void button2_Click(object sender, EventArgs e)
{
//you may want to reset any global variables or any other
//housekeeping before calling the form load method
Form1_Load(sender, e);
}
private void Form1_Load(object sender, EventArgs e)
{
if (sender is Button)
{
//the message box will only show if the sender is a button
MessageBox.Show("You Clicked a button");
}
}
歡迎來到StackOverflow。只有代碼在他們的答案往往會被標記爲刪除,因爲他們是「低質量」。請閱讀關於回答問題的幫助部分,然後考慮在答案中添加一些評論。 – Graham
Application.Restart();可能會解決 – Burimi
,但它會顯示一個閃爍(它的關閉和打開表單),這是該職位要求避免的。 – Sandy