T
Trollpower
Dear NG,
ive got two Forms, lets say A and B. Form A shows Form B. I put some
buttons on both forms. Addionally i put them at the same location. If
I click a Button on form B twice the second click gets passed to form
A. This happens as followed: After clicking the button on form B the
form gets closed after some function gets called. In the meantime the
second click gets passed to the button on form B. But due to some
mishappenings the second click wont be ignored, it gets passed to the
button with the same location on form A.
Does anyone knows how to solve this problem, so that i only get the
click once and only on the button i made the click on? Please note: I
dont want to diasable all the controls on Form A to solve the problem.
Thanks in advance
Jens
Here is the sample code:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
namespace Formstest
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.MainMenu mainMenu1;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region blah
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
//
// button1
//
this.button1.Location = new System.Drawing.Point(144, 16);
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(0, 200);
this.button2.Size = new System.Drawing.Size(240, 72);
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
}
#endregion
static void Main()
{
Application.Run(new Form1());
}
private void button2_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Hello World");
}
private void button1_Click(object sender, System.EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
namespace Formstest
{
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
public Form2()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region blah
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
//
// button1
//
this.button1.Location = new System.Drawing.Point(0, 208);
this.button1.Size = new System.Drawing.Size(240, 64);
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form2
//
this.Controls.Add(this.button1);
this.Text = "Form2";
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
Thread.Sleep(2000);
this.Close();
}
}
}
ive got two Forms, lets say A and B. Form A shows Form B. I put some
buttons on both forms. Addionally i put them at the same location. If
I click a Button on form B twice the second click gets passed to form
A. This happens as followed: After clicking the button on form B the
form gets closed after some function gets called. In the meantime the
second click gets passed to the button on form B. But due to some
mishappenings the second click wont be ignored, it gets passed to the
button with the same location on form A.
Does anyone knows how to solve this problem, so that i only get the
click once and only on the button i made the click on? Please note: I
dont want to diasable all the controls on Form A to solve the problem.
Thanks in advance
Jens
Here is the sample code:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
namespace Formstest
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.MainMenu mainMenu1;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region blah
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
//
// button1
//
this.button1.Location = new System.Drawing.Point(144, 16);
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(0, 200);
this.button2.Size = new System.Drawing.Size(240, 72);
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
}
#endregion
static void Main()
{
Application.Run(new Form1());
}
private void button2_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Hello World");
}
private void button1_Click(object sender, System.EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
namespace Formstest
{
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
public Form2()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region blah
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
//
// button1
//
this.button1.Location = new System.Drawing.Point(0, 208);
this.button1.Size = new System.Drawing.Size(240, 64);
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form2
//
this.Controls.Add(this.button1);
this.Text = "Form2";
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
Thread.Sleep(2000);
this.Close();
}
}
}