RTL 语言中的 C# CustomFormat DateTimePicker

发布于 2024-10-18 08:27:34 字数 829 浏览 7 评论 0原文

我得到了 DateTimePicker 控件。 我使用以下代码来设置控件的格式:

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "HH:mm";

它解决了一个问题。我的计算机文化语言是RTL语言(希伯来语),所以我在控件中看到的时间格式是“mm:HH”,尽管我写的是“HH:mm”。这是由 RTL 文化引起的,所以我尝试了两种方法来解决它,但没有一种有效/完全有效。

我尝试过:

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

但根本不起作用。

我还尝试使用以下代码来检测其是否为 RTL 语言:

CultureInfo.TextInfo.IsRightToLeft

然后将格式字符串从“HH:mm”反转为“mm:HH”(如果是 RTL 语言),但后来我发现了另一个问题 - 在 XP 中如果它的RTL语言它会写出正确的格式..所以是的我可以检测它是否是XP但我认为对于简单的需求来说代码太多了...

有更简单的解决方案吗?

谢谢!。

I got DateTimePicker control.
I used the following code to set the format of the control:

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "HH:mm";

it worked with one problem. My computer culture language is RTL language (hebrew), so I see the format of the time in the control like that "mm:HH" althought I wrote "HH:mm". It caused by the RTL culture, So I tried two ways to solve it but none of them worked / worked completely.

I tried:

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

and it didnt work at all.

I also tried to detect wheter its RTL language or not by using this code:

CultureInfo.TextInfo.IsRightToLeft

and then to reverse the format string from "HH:mm" to "mm:HH" (if its rtl language) but then I discovered another problem - in XP if its RTL language it will write the right format.. so yeah I can detect if its XP or not but I think this is too much code for simple need...

Is there easier solution?

Thanks!.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱咩 2024-10-25 08:27:34

Windows 7 和 Server 2008 R2 中的 RTL 语言存在 DTP 损坏。知识库文章在这里,论坛主题在这里。对于你的情况来说,这并不完全是灌篮高手,但仍然令人信服。尝试它链接到的修补程序。

There was DTP breakage for RTL languages in Windows 7 and Server 2008 R2. The KB article is here, the forum thread that got that ball rolling is here. Not exactly a slamdunk for your case but compelling nonetheless. Try the hotfix it links to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文