Hi rajeshlokayata,
Here is a runable example - just copy to a new WindowsForms project and replace Program.cs content with the following code:
using System;
using System.Windows.Forms;
namespace OpenFormAfter5Seconds
{
static class Program
{
[STAThread]
static void Main()
{
Form form = new Form();
Button button = new Button();
button.Text = "Press for 5 s";
button.Dock = DockStyle.Fill;
form.Controls.Add(button);
Timer timer = new Timer();
timer.Interval = 5000;
button.MouseDown += delegate(object sender, MouseEventArgs mea)
{
timer.Start();
};
button.MouseUp += delegate(object sender, MouseEventArgs mea)
{
timer.Stop();
};
timer.Tick += delegate(object sender, EventArgs e)
{
timer.Stop();
MessageBox.Show(form, "You Pressed the Button for 5 Seconds!", "Dialog");
};
Application.Run(form);
}
}
}
So in reality you would design your form in the Forms designer, attach eventhandlers to your button (MouseDown/Up or KeyDown/Up), Start the timer on ButtonDown, Stop it on ButtonUp (for the cases the user didn't hold the button for 5 Seconds), and if the timer interval has elapsed show your dialog!