Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • clicking window application button more than ones will automatically clicks the same location button of next form

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 170
    Comment on it

    How to resolve "If we click window application button more than ones at a time then it automatically click the same location button of next form"

    Sometime we face an issue in window application that if two windows have same Start Position and same button location then if we click first form button more than one time then it also automatically click the same location button on another form.
    To resolve this issue we can use "Application.DoEvents()" method.

    When more then one more events occurred, its all added in the queue, and when one event process, all other events are wait in the queue.

    But if we add DoEvents in our code,then code can handle the other events.

    Form1:

    public partial class Form1 : Form
    {
    	public Form1()
    	{
    		InitializeComponent();
    	}
    	private void Form1_Load(object sender, EventArgs e)
    	{
    		button1.Location = new Point(98, 67);
    	}
    	private void button1_Click(object sender, EventArgs e)
    	{
    		button1.Enabled = false;
    		// your code that take some processing time
    		this.Hide();
    		Application.DoEvents();
    		Form2 form2 = new Form2();
    		form2.Show();
    	}
    }

    Form2:

    public partial class Form2 : Form
    {
        public Form1 form1;
        public Form2()
        {
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
             button1.Location = new Point(98, 67);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("I am in second form");
        }
    }

    Hope this code will help you.Thanks.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: