Click here to Skip to main content
15,912,457 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
hi guys
i have some question
i want to add NumericUpDown tool to my project but i want to display time
and i want change the value of time by this tool
i want to be like( date and time setting) in PC when you want change the time.
please help....
Posted
Updated 26-Feb-14 13:11pm
v3
Comments
Sergey Alexandrovich Kryukov 26-Feb-14 17:58pm    
Time of what?... In what limits do you want to change time? Why? What's wrong with DateTimePicker?
If these are just seconds (milliseconds, hours, anything decimal, fractional or not), you would not need any help.
—SA
Mohamed Ragheb 26-Feb-14 18:37pm    
but how ????
Sergey Alexandrovich Kryukov 26-Feb-14 19:03pm    
What do you mean "how"? Do you know how to use this control in general? It is explained on its MSDN page...
—SA
Mohamed Ragheb 26-Feb-14 19:32pm    
Thank you've finished the project
Sergey Alexandrovich Kryukov 26-Feb-14 19:38pm    
Answered, please see my answer.
—SA

You are "buying water by the river:" Win Forms makes what you want here very easy:

1. put a DateTimePicker on your Form: 'TimePicker24

Set these Properties of the DateTimePicker:

Format: Custom
CustomFormat: HH: mm: ss tt
ShowTextBox: False
ShowUpDown: True
Checked: False

2. put a TextBox on your Form: 'TimeTextBox

3. create a ValueChanged EventHandler for the DateTimePicker:
C#
private void TimePicker24_ValueChanged(object sender, EventArgs e)
{
    TimeTextBox.Text = TimePicker24.Text;
}
You now have a fully functional 24-hour style time picker. Of course, you can set-up its initial properties as you wish.

I suggest you keep the current time value selected in the DateTimePicker ... as a DateTime value ... in a variable for further use:
C#
private DateTime CurrentTime;

private void TimePicker24_ValueChanged(object sender, EventArgs e)
{
    CurrentTime = TimePicker24.Value;
    TimeTextBox.Text = TimePicker24.Text;
}
 
Share this answer
 
Comments
Mohamed Ragheb 27-Feb-14 8:54am    
Thank you very much ... it is working successfully ( BillWoodruff )
Mohamed Mahmoud Abo Raghep wrote:
I mean, I need to pass the time chosen to textBox.
You need to handle the event NumericUpDown.ValueChanged:
http://msdn.microsoft.com/en-us/library/system.windows.forms.numericupdown.valuechanged%28v=vs.110%29.aspx[^].

In the handler of this event, you can read the current value of your NumericUpDown control and update the property TextBox.Text of your text box accordingly.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900