本文介绍了动态创建datetimepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一天的工作时间
我正在使用一个datetimepicker来获取输入时间,并使用一个datetimepicker来获取退出时间.
使用这些时间,我可以通过公式退出时间-进入时间来计算总时数
我想要以下格式

entryTime:timePicker;退出时间:时间选择器;一天中的小时:退出条目


当我在运行时单击此+按钮时,其他行应显示为

entryTime:timePicker;退出时间:时间选择器;一天中的小时:退出条目
entryTime:timePicker;退出时间:时间选择器;一天中的小时:退出条目

等等
如何动态添加时间选择器的这一行

I want to get working hours of day
i m using one datetimepicker for taking entry time and one datetimepicker for taking exit time.
using these times i calculate total hours by formula Exit time-Entry time
i want following format

entryTime : timePicker ; exit time : Timepicker; hours of day:exit-entry


when i click this + button at run time other row should appear as

entryTime : timePicker ; exit time : Timepicker; hours of day:exit-entry
entryTime : timePicker ; exit time : Timepicker; hours of day:exit-entry

so on
how to add this row that is timepickers dynamically

推荐答案

private void button1_Click(object sender, EventArgs e)
{
    DateTimePicker dtp = new DateTimePicker();
    //add the new datetimepicker below the previous one
    dtp.Location = new Point(dateTimePicker1.Location.X, dateTimePicker1.Location.Y+25);
    Button btn = new Button(); // add a new button
    btn.Size = button1.Size; //set button size
    btn.Text = "+"; // set button text
    btn.Location = new Point(button1.Location.X, button1.Location.Y+25);
    this.Controls.Add(dtp);
    this.Controls.Add(btn);
}



如果愿意,您可以在表单中添加更多类似的控件,对吗?
另外,如果您真的觉得这很有帮助,请对那些代表您工作的人表示感谢;例如投票或接受答案. ;)



You would be able to add more controls like this to your form if you want, Won''t you?
Also, please if you really find this one helpful , then show some appreciation to those who are working on behalf of you ; like voting or accepting the answer. ;)



这篇关于动态创建datetimepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 18:22