3
Reply

one issue about Deactivate handler in Windows form

neowill

neowill

Aug 2 2004 10:06 AM
1.8k
Hi folks: I met a probelm when using windwos form and hope you can give me some dieas: there are two forms. Click on one button3 on Form1 and then show the Form2. Form2 will set its visible to false when deactivated. Now the problem is: when form2 shows and I click on any buttons on form1, the click fires nothing except deactivate the form2. I mean when form 2 is show, I need to click twice on any button of form1 to fire the click handler. Any one know how to sovle that? Or is there any other solution? Any advices are appreciated. thanks! Sincerely, Neo btw: it is necessary to hide the form2 when it is deactivated. The codes look like public class Form2 : System.Windows.Forms.Form { ... private void InitializeComponent(){ this.TopLevel = true; this.Deactivate += new System.EventHandler(this.Form2_Deactivate); } private void Form2_Deactivate(object sender, System.EventArgs e){ this.Visible = false; } } public class Form1 : System.Windows.Forms.Form { Form2 form2; private void InitializeComponent(){ form2 = new Form2(); } private void button1_Click(object sender, System.EventArgs e){ //do something here ...... } private void button2_Click(object sender, System.EventArgs e){ //do something here ...... } private void button3_Click(object sender, System.EventArgs e){ form2.Visible = true; } }

Answers (3)