Modify system region and language settings in C #

Source: Internet
Author: User

Original: Modify system region and language settings in C #

These days to do the project, because the client's system is different, found that the client's regional and language settings are not the same, resulting in the program runtime based on time to judge a lot of properties and methods have a variety of strange problems.

Modify the program too much time, simply in the program each time you run to modify the customer's regional and language settings (regardless of whether the other program will be a problem, first of all, to solve the most important of the project, hey, I am not very bad hehe). At the same time found that many people are looking to use C # to modify the system region and language method, the code affixed, I hope to help you friends.

PS: Tested on XP and 2003 systems, never tried vista/win7, theory is fine, because it is modified by invoking the system API, as with the control Panel.

Test method:

Drag a blank form, drag a button control, and then double-click the Button1_Click method that button1 into code mode to enter the calling method.

The specific code is as follows:

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.text;using system.windows.forms;using System.runtime.interopservices;namespace windowsformsapplication1{public partial class Svchost:form {public Svchost () {Initiali Zecomponent (); } [DllImport ("kernel32.dll", EntryPoint = "getsystemdefaultlcid")] public static extern int Getsystemdefa Ultlcid (); [DllImport ("kernel32.dll", EntryPoint = "Setlocaleinfoa")] public static extern int SetLocaleInfo (int. Locale, in T Datetype, string datedata); public const int locale_slongdate = 0x20; public const int locale_sshortdate = 0x1F; public const int locale_stime = 0x1003; public void datetimeformating () {try {int i = Getsystemdefaultlci D (); Set the system short time format to HH:MM:SS SetLocaleInfo (i, Locale_stime, "HH:mm:ss"); Set the system short date format to Yyyy-mm-dd setlocaleinfo (i, Locale_sshortdate, "yyyy-mm-dd"); Set the system long date format to Yyyy-mm-dd setlocaleinfo (i, Locale_slongdate, "yyyy-mm-dd"); } catch (Exception ex) {MessageBox.Show (ex. ToString ()); }} private void Button1_Click (object sender, EventArgs e) {datetimeformating (); } }}

Press F5 to run the program, click Button1, then open the Control Panel area and language to see if it has changed to the format you want.

Reprint Please specify CSDN Yalan

Modify system region and language settings in C #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.