C# 如何在 .Net 中将文化更改为 DateTimepicker 或日历控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/241964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change culture to a DateTimepicker or calendar control in .Net
提问by Oscar Cabrero
How to set internationalization to a DateTimepicker
or Calendar WinForm
control in .Net when the desire culture is different to the one installed in the PC?
当欲望文化与安装在PC中的文化不同时,如何在.Net中将国际化设置为一个DateTimepicker
或Calendar WinForm
控件?
采纳答案by Jonas Lincoln
It doesn't seem to be possible to change the culture. See this KB article.
改变文化似乎是不可能的。请参阅此知识库文章。
回答by Hapkido
For DateTimePicker
对于日期时间选择器
dtp.Format = DateTimePickerFormat.Custom;
dtp.CustomFormat = "yyyy-MM-dd"; // or the format you prefer
回答by Bigballs
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("fr");
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
回答by heejong
I think there is detour.
我认为有绕路。
- set event handler "ValueChanged"
code
dateTimePicker.Format = DateTimePickerFormat.Custom; string[] formats = dateTimePicker.Value.GetDateTimeFormats(Application.CurrentCulture); dateTimePicker.CustomFormat = formats[0];
- 设置事件处理程序“ValueChanged”
代码
dateTimePicker.Format = DateTimePickerFormat.Custom; string[] formats = dateTimePicker.Value.GetDateTimeFormats(Application.CurrentCulture); dateTimePicker.CustomFormat = formats[0];
回答by KaDim
Based on previous solution, I think the better is:
基于以前的解决方案,我认为更好的是:
dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;
回答by user12146889
Use the telerik radDateTimePicker and write this code , after InitializeComponent(), and Instead of "fa-IR" use your culture.
使用 Telerik radDateTimePicker 并在 InitializeComponent() 之后编写此代码,而不是“fa-IR”使用您的文化。
Application.CurrentCulture = new CultureInfo("fa-IR");
radDateTimePicker1.Format = DateTimePickerFormat.Custom;
radDateTimePicker1.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;