I create a simple form that pops up a dialog box when you run it, but i cannot close it programmatically. Can anyone help me with that?
Label lb = new Label();
Form frm = new Form();
lb.Left = 100;
lb.Top = 44;
frm.Controls.Add(lb);
frm.ShowDialog();
System.Threading.Thread.Sleep(2000);
After ..Sleep(2000) i want it to close. I tried:
frm.close();frm.dispose();frm.visible = false;
Thanks in advance!
You can use something like this inside you form class:
protected override async void OnLoad(EventArgs e)
{
base.OnLoad(e);
await Task.Delay(2000);
Close();
}
Inside the OnLoad
method run a task that wait 2000 ms and close the form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With