简体   繁体   中英

button.performclick(); not working in form1 minimized state c#

I am trying to add a code that auto clicks on a button after certain time so i put only

button1.performclick();

its working but when form1 is in minimize state, its not working

i put the following code but its not working

if (this.WindowState == FormWindowState.Minimized)
            {
                button1.PerformClick();
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                button1.PerformClick();
            }

Help wanted !

What I did in a similar situation in VB where PerformClick wasn't working if the form is minimized was I created a function and pasted all the button click code in that function. Then I simply call the function from the button click's code instead of using PerformClick.

I'd rather create a void than a click event, and i'd call it from the click event too

like this

public void clickedbutton1()
{
    //your code for buttonclick
}
if (this.WindowState == FormWindowState.Minimized)
{
    clickedbutton1();
    this.WindowState = FormWindowState.Normal;
}
else
}
    clickedbutton1();
}
private void Button1_Click(object sender, EventArgs e)
{
    clickedbutton1();
}

Best I can think of is doing something like this.

private void Form1_Load(object sender, EventArgs e)
        {
            Application.DoEvents();
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM