Hi
I am a Fresher, am creating a windows application in which i have two forms.
In first form i created a button(Named as Break) and timer which will start on load.
when he clicks on Break button he will be redirected to a login page.
As soon as he clicks on the Break button the timer should pause.
and when the person login's , he will be back on first form, now the suspended timer should resume.
I am creating this app to count the no of working hours user worked a day.
Please Help!!
Thank you,
Selva GanapathyPosted Mar 13, 2014, 4:56 AM
You can meet this requirement by simply pass the mainform object (or need timer object) to the login form as I implemented in the following code. So that you can stop the timer while opening the loginpage in main form and resume the timer by the object passed in the login page itself.
Mainform:
public partial class Form1 : Form
{
public Timer t = new Timer();
public Form1()
{
InitializeComponent();
t.Interval = 500;
t.Tick += t_Tick;
t.Start();
}
void t_Tick(object sender, EventArgs e)
{
this.label1.Text = (Convert.ToInt16(this.label1.Text) + 1).ToString();
}
private void button1_Click(object sender, EventArgs e)
{
loginpage loginPage = new loginpage(this);
loginPage.Show();
t.Stop();
}
}
Login Form:
public partial class loginpage : Form
{
Form mainform = null;
public loginpage(Form form )
{
InitializeComponent();
mainform = form;
}
private void button3_Click(object sender, EventArgs e)
{
MessageBox.Show("UserName : tamil and password : tamil");
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text == "tamil")
{
if (this.textBox2.Text == "tamil")
{
(mainform as Form1).label2.Text = "Hi, Tamil! you are successfully logged in";
(mainform as Form1).t.Start();
this.Close();
}
else
{
MessageBox.Show("wrong password");
}
}
else
{
MessageBox.Show("wrong username");
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
Regards,
Selva Ganapathy K
Narender ReddyPosted Mar 13, 2014, 8:50 AM
Selva GanapathyPosted Mar 13, 2014, 7:09 AM
Welcome. You can change the target framework version into 4.0 instead of 4.5 in CS file by editing.
Regards,
Selva Ganapathy K
Narender ReddyPosted Mar 13, 2014, 6:23 AM
Thanks for the support.
The solution which u created is in newer version of VS.
I am using MS2010.