Natan1978
asked on
counter in c# / wpf
hello
i want to creat counter that after user open application so it is start count his time he is use app and after xxx time messge box jump and ask him to approve that he is working on app and not go out, and other option is shutdown app.
how i do this?
thanks
i want to creat counter that after user open application so it is start count his time he is use app and after xxx time messge box jump and ask him to approve that he is working on app and not go out, and other option is shutdown app.
how i do this?
thanks
ASKER
hello
i did this part but it is only show timer
i need that when application start so it will count xxx min's and when is end so it will ask user with messgebox if to contion work or to close app
this is what i done
private void dispatcherTimer_Tick(objec t sender, EventArgs e)
{
lblsleep.Content =(DateTime.Now.Hour.ToStri ng() + ":" +
DateTime.Now.Second.ToStri ng());
}
plz help me make it to what i need
thanks
i did this part but it is only show timer
i need that when application start so it will count xxx min's and when is end so it will ask user with messgebox if to contion work or to close app
this is what i done
private void dispatcherTimer_Tick(objec
{
lblsleep.Content =(DateTime.Now.Hour.ToStri
DateTime.Now.Second.ToStri
}
plz help me make it to what i need
thanks
You can get result of messagebox by dialogresult
DialogResult result = MessageBox.Show("Do you want close the app?", "Hi",
MessageBoxButtons.OKCancel );
switch (result)
{
case DialogResult.OK:
{
this.Close();
break;
}
case DialogResult.Cancel:
{
//your code here
break;
}
}
http://www.dotnetperls.com/messagebox-show
http://www.dotnetperls.com/dialogresult
DialogResult result = MessageBox.Show("Do you want close the app?", "Hi",
MessageBoxButtons.OKCancel
switch (result)
{
case DialogResult.OK:
{
this.Close();
break;
}
case DialogResult.Cancel:
{
//your code here
break;
}
}
http://www.dotnetperls.com/messagebox-show
http://www.dotnetperls.com/dialogresult
ASKER
yes but impletent the counter plz inside code
thanks
thanks
You set timer interval:
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
-> aTimer.Interval = Counter*1000*60; counter in minuter.
http://msdn.microsoft.com/en-us/library/system.timers.timer.interval.aspx
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
-> aTimer.Interval = Counter*1000*60; counter in minuter.
http://msdn.microsoft.com/en-us/library/system.timers.timer.interval.aspx
ASKER
wher i insert this?
i want to show the time run reverce that use show this all the time
i want to show the time run reverce that use show this all the time
ASKER
plz
i wait you
thanks
i wait you
thanks
you use datetime substract function:
http://stackoverflow.com/questions/5177002/how-to-subtract-a-datetime-from-another-datetime.
You declare a variable DateTime
in form constract or onform_loading add a code line :
DateTime StartTime= DateTime.Now;
private void dispatcherTimer_Tick(objec t sender, EventArgs e)
{
lblsleep.Content =DateTime.Now.ToString("HH :mm:ss");
int counter = DateTime.Now.SubStract(Sta rtTime).Mi nutes ;
if (counter == YourCounter)
{
DialogResult result = MessageBox.Show("Do you want close the app?", "Hi",
MessageBoxButtons.OKCancel );
switch (result)
{
case DialogResult.OK:
{
this.Close();
break;
}
case DialogResult.Cancel:
{
//your code here
break;
}
}
}
}
http://stackoverflow.com/questions/5177002/how-to-subtract-a-datetime-from-another-datetime
http://stackoverflow.com/questions/5177002/how-to-subtract-a-datetime-from-another-datetime.
You declare a variable DateTime
in form constract or onform_loading add a code line :
DateTime StartTime= DateTime.Now;
private void dispatcherTimer_Tick(objec
{
lblsleep.Content =DateTime.Now.ToString("HH
int counter = DateTime.Now.SubStract(Sta
if (counter == YourCounter)
{
DialogResult result = MessageBox.Show("Do you want close the app?", "Hi",
MessageBoxButtons.OKCancel
switch (result)
{
case DialogResult.OK:
{
this.Close();
break;
}
case DialogResult.Cancel:
{
//your code here
break;
}
}
}
}
http://stackoverflow.com/questions/5177002/how-to-subtract-a-datetime-from-another-datetime
ASKER
fix your code:
DateTime StartTime;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DateTime StartTime= DateTime.Now;
}
private void dispatcherTimer_Tick(objec t sender, EventArgs e)
{
DateTime StartTime= DateTime.Now;
lblsleep.Content =DateTime.Now.ToString("HH :mm:ss");
int counter = DateTime.Now.SubStract(Sta rtTime).Mi nutes ;
if (counter == YourCounter)
{
DialogResult result = MessageBox.Show("Do you want close the app?", "Hi",
MessageBoxButtons.OKCancel );
switch (result)
{
case DialogResult.OK:
{
this.Close();
break;
}
case DialogResult.Cancel:
{
//your code here
break;
}
}
}
DateTime StartTime;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DateTime StartTime= DateTime.Now;
}
private void dispatcherTimer_Tick(objec
{
DateTime StartTime= DateTime.Now;
lblsleep.Content =DateTime.Now.ToString("HH
int counter = DateTime.Now.SubStract(Sta
if (counter == YourCounter)
{
DialogResult result = MessageBox.Show("Do you want close the app?", "Hi",
MessageBoxButtons.OKCancel
switch (result)
{
case DialogResult.OK:
{
this.Close();
break;
}
case DialogResult.Cancel:
{
//your code here
break;
}
}
}
ASKER
Hi
What is counter= your counter
Ehat is this?
What is counter= your counter
Ehat is this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is ok o understand now
I will try this
Can you help with my quation about export wpf form to pdf?
Thanks
I will try this
Can you help with my quation about export wpf form to pdf?
Thanks
ASKER
thank you
http://www.c-sharpcorner.com/uploadfile/mahesh/timer-in-wpf/