Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I make the ContextMenu to close after a set time interval?

To automatically close the context menu after a set time interval, you can use a Timer and send an Esc keystroke after the desired time interval as shown:

[C#]

private void timer1_Tick(object sender, System.EventArgs e)
{
SendKeys.Send("{ESC}");
timer1.Stop();
}

private void contextMenu1_Popup(object sender, System.EventArgs e)
{
//set interval to 5 seconds
timer1.Interval = 5000;
timer1.Start();
}

Contributed from George Shepherd's Windows Forms FAQ