DateTimePicker计算到TextBox [英] DateTimePicker Calculation to TextBox

查看:96
本文介绍了DateTimePicker计算到TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助。

我试图在文本框中显示不同的结果。无论我尝试了什么代码,仍然没有导致我的文本框。我正在使用datetimepicker1(dtpIn1)来触发结果。

I'm trying to show time different result in a textbox. No matter what code i tried, still no result in my textbox. I'm using datetimepicker1 (dtpIn1) to trigger the result.

private void dtpIn1_ValueChanged(object sender, EventArgs e)
{
TimeSpan ts = this.dtpIn1.Value - this.dtpOut1.Value;
this.txtTotal1.Text = ts.ToString();            

//txtTotal1.Text = new TimeSpan(Math.Abs(dtpIn1.Value - dtpOut1.Value)).ToString();        
}

注意:评论是我的第二个代码。

Note: The comment is my second code.

请帮忙。




推荐答案

最好的解决方法之一是首先在代码中进行测试,例如

One of the best ways to work this is by first testing this in code e.g.

var d1 = DateTime.Now;
var d2 = DateTime.Now.AddHours(8);
var result = d1 - d2;
Console.WriteLine(result.ToString());
Console.WriteLine(result.Hours.ToString());

哪个产生-8

理想情况下,开发人员将排除控件的问题,例如DataTimePicker和编写代码意味着可重复的测试。 

Ideally a developer will rule out issues with controls such as a DataTimePicker plus writing code means a repeatable test. 


这篇关于DateTimePicker计算到TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆