如何在 Winform 应用程序中设置应用程序范围的文化信息

发布于 2024-12-27 23:30:49 字数 533 浏览 2 评论 0原文

我试图在我的一个 winform 应用程序(VB .net)的开头设置文化信息。代码是:

Public Sub New()
    System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-CA")
    System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("en-CA")
    ' This call is required by the Windows Form Designer.
    InitializeComponent()


    ' Add any initialization after the InitializeComponent() call.

End Sub

但是,后续表单中的日期时间选择器显示“dd-MM-yyyy”类型的日期格式。怎样才能设置正确呢?我缺少什么步骤。

I trying to set cultural information at the beginning of one of my winform application (VB .net). The code are:

Public Sub New()
    System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-CA")
    System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("en-CA")
    ' This call is required by the Windows Form Designer.
    InitializeComponent()


    ' Add any initialization after the InitializeComponent() call.

End Sub

However, datetime picker in the subsequent form shows date format of the type "dd-MM-yyyy". How can I set is right? What steps I am missing.

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

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

发布评论

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

评论(1

绮筵 2025-01-03 23:30:49

不幸的是,新线程的默认区域性没有应用程序范围的设置。线程的默认区域性是由 Windows 在创建时设置的。

另请查看此知识库文章< /a>,虽然很旧,但我相信仍然适用。 DatePicker 使用 Windows 区域设置而不是 currentCulture。

您可以直接更改 DatePicker 的设置以使其按您的意愿显示。

比如:

DatePicker1.Format = DateTimePickerFormat.Custom
DatePicker1.CustomFormat = "MM-dd-yyyy" 

我想如果我有很多这样的东西,我可能会创建自己的类来继承 DatePicker 并在构造函数中设置它。

Unfortunately there's no application-wide setting for the default culture for new threads. The default culture of a thread is set by Windows when it is created.

Also check out this KB Article, which is old but I believe still applies. The DatePicker uses windows regional settings rather than currentCulture.

You can alter the settings for a DatePicker directly to make it display as you wish.

Something like:

DatePicker1.Format = DateTimePickerFormat.Custom
DatePicker1.CustomFormat = "MM-dd-yyyy" 

I think if I had many of these I may make my own class to inherit from DatePicker and set that in the constructor.

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