C#WinForms DateTimePicker自定义格式 [英] C# WinForms DateTimePicker Custom Format

查看:124
本文介绍了C#WinForms DateTimePicker自定义格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有一个 DateTimePicker 。我希望格式的一部分适当地包含今天,明天等。我有一个简单的实现来计算值(这里还有一个更好的方法:此处),但我想采用该实现并将其值直接放入 DateTimePicker CustomFormat 属性中c>。

I have a DateTimePicker on my form. I'd like part of the format to include "today", "tomorrow" etc as appropriate. I've got a simple implementation to work out the value (and there are much better ones here) but I'd like to take that implementation and put the value directly into the CustomFormat property of the DateTimePicker.

例如,给定以下格式:

dateTimePicker.CustomFormat = "dd MMM yyyy (YTT) HH:mm";

要在2011年4月16日12:00的运行时显示以下内容:

To produce the following display at runtime on 16th April 2011 at 12:00:

"16 Apr 2011 (today) 12:00"

我希望这涉及到构建 IFormatProvider / ICustomFormatter 的实现和 hacking 定制 CurrentCulture 来使用它。

I expect this is something involving building a IFormatProvider/ICustomFormatter implementation and hacking customising the CurrentCulture to use it.

非常感谢。

推荐答案

在自定义日期格式字符串中的静态文本周围使用'

Use ' around the static text in a custom date format string.

 string ytt = "today"; //Simple example... Update to determine yesterday, today or tomorrow.

 this.dateTimePicker.CustomFormat = "dd MMM yyyy '(" + ytt + ")' HH:mm";

这篇关于C#WinForms DateTimePicker自定义格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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