How to open new form in specific time using C# winform [closed]
Clash Royale CLAN TAG#URR8PPP
How to open new form in specific time using C# winform [closed]
I have a form, on button click event it is open. Now I want to open it on time basis of PC. when Time gets 10.00 in the morning then the form should automatically open within MDI parent. When Time gets 04:00 in evening then it should close automatically....
Please help
This question appears to be off-topic. The users who voted to close gave this specific reason:
I have tried so many times but unable to make it....... please help
– Nityanand Vishwakarma
Aug 8 at 7:30
Then you should post what you've tried. We can help assist
– FrankerZ
Aug 8 at 7:31
1 Answer
1
To manage time, you need to take timer control. Below sample code will help you to achieve your requirement.
public partial class frmStackAnswers : Form
Timer tmr = new Timer(); //Timer to manage time
Form childForm; //Child form to display
public frmStackAnswers()
InitializeComponent();
Load += frmStackAnswers_Load;
void frmStackAnswers_Load(object sender, EventArgs e)
tmr.Interval = 60000;
tmr.Tick += tmr_Tick;
tmr.Start();
void tmr_Tick(object sender, EventArgs e)
//Start child form between 10 AM to 4 PM if closed
if (DateTime.Now.Hour > 10 && DateTime.Now.Hour < 16 && childForm == null)
childForm = new Form();
childForm.Show();
//Close child form after 4 PM if it is opened
else if (DateTime.Now.Hour > 16 && childForm != null)
childForm.Close();
childForm = null;
Have you done any research, or experimented with any timers?
– FrankerZ
Aug 8 at 7:25