按Form1內的button1可以開啟Form2,
為了避免再次按下button1時會重覆開啟Form2,
以及將Form2縮小後,
按button1要如何讓Form2跳出來,
static Form2 form2 = null;
private void button1_Click(object sender, EventArgs e)
{
/*判斷Form2是否有被開啟*/
if (form2 == null)
{
form2 = new Form2();
form2.Show();
/*Create an event where the form is closed(dispose)*/
form2.Disposed += new EventHandler(form2_Disposed);
}
else
{
/*Set form to default size*/
form2.WindowState = FormWindowState.Normal;
/*把form帶到疊置順序的前面(讓縮小的Form2跳出來)*/
form2.BringToFront();
}
}
/*關閉Form時會觸發的事件*/
void form2_Disposed(object sender, EventArgs e)
{
form2 = null;
}
範例程式下載
#C##重複開視窗#視窗#視窗縮小
沒有留言:
張貼留言