在c#中使用NumericUpDown工具和时间 [英] use NumericUpDown tool with time in c#
问题描述
嗨伙计
i有一些问题
i希望将NumericUpDown工具添加到我的项目中,但我希望显示时间
我希望更改这个工具的时间价值
i想要在PC上想要改变时间(日期和时间设置)。
请帮助....
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....
推荐答案
你是在河边买水:Win Forms让你想要的东西变得非常简单:
1.在表单上放置一个DateTimePicker:'TimePicker24
设置DateTimePicker的这些属性:
格式:自定义
CustomFormat:HH:mm:ss tt
ShowTextBox:False
ShowUpDown:True
选中:错误
2.在表格上放置一个TextBox:'TimeTextBox
3.创建一个DateTimePicker的ValueChanged EventHandler:
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:
private void TimePicker24_ValueChanged(object sender, EventArgs e)
{
TimeTextBox.Text = TimePicker24.Text;
}
您现在拥有一个功能齐全的24小时式时间选择器。当然,您可以根据需要设置其初始属性。
我建议您将当前时间值保留在DateTimePicker中...作为DateTime值...在变量中供进一步使用:
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:
private DateTime CurrentTime;
private void TimePicker24_ValueChanged(object sender, EventArgs e)
{
CurrentTime = TimePicker24.Value;
TimeTextBox.Text = TimePicker24.Text;
}
I意思是,我需要将选择的时间传递给textBox。
I mean, I need to pass the time chosen to textBox.
你需要处理事件 NumericUpDown.ValueChanged
:
http://msdn.microsoft.com/en -us / library / system.windows.forms.numericupdown.valuechanged%28v = vs.110%29.aspx [ ^ ]。
在此事件的处理程序中,您可以读取 NumericUpDown
控件的当前值并更新属性 TextBox.Text
相应的文本框。
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.
这篇关于在c#中使用NumericUpDown工具和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!