Results 1 to 6 of 6

Thread: [RESOLVED] VB.net change system locale

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2017
    Posts
    199

    Resolved [RESOLVED] VB.net change system locale

    Hello,
    can someone help me out how can it be made to change windows system locale option using vb.net application.

    Example:
    1 combobox - inside 3 languages ( English, Japan, Romania )
    1 button - activate the executable with selected language

    i have read some topics from google, but i cannot find some good way, that's why i wanted to ask if someone that knows better this how to be made correctly would be grateful.

    i had found one similar solution like:
    Code:
    Imports System.Globalization
    ''' <summary>
    ''' Requires 
    '''    1 ComboBox: cboCultures
    '''    2 TextBoxes: TextBox1, TextBox2
    '''    1 DateTimePicker: DateTimePicker1
    ''' </summary>
    Public Class Form1
        ' Used to set cboCultures selected item and for restoring the current culture
        Private OriginalCultureName As String = ""
        Private OriginalCultureIndex As Integer = 0
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            OriginalCultureName = Application.CurrentCulture.Name
            DateTimePicker1.Format = DateTimePickerFormat.Custom
    
            cboCultures.DisplayMember = "DisplayName"
            cboCultures.ValueMember = "Code"
            cboCultures.DropDownStyle = ComboBoxStyle.DropDownList
    
            Dim CultureList =
                (
                    From cultureitem In CultureInfo.GetCultures(CultureTypes.SpecificCultures)
                    Order By cultureitem.EnglishName
                    Select New With
                           {
                               .DisplayName = cultureitem.EnglishName,
                               .Code = cultureitem.Name
                           }
                ).ToList
    
            cboCultures.DataSource = CultureList
    
            ' get current culture so we can select it in cboCultures
            Dim item =
                (
                    From T In CultureList _
                    .Select(
                        Function(cultureitem, indexer)
                            Return New With {.Index = indexer, .Name = cultureitem.Code}
                        End Function)
                    Where T.Name = OriginalCultureName
                ).First
    
            OriginalCultureIndex = item.Index
            cboCultures.SelectedIndex = OriginalCultureIndex
            Demo()
        End Sub
    
        Private Sub cmdChange_Click(sender As Object, e As EventArgs) Handles cmdChange.Click
            Application.CurrentCulture = New CultureInfo(cboCultures.SelectedValue.ToString)
            Demo()
        End Sub
        ''' <summary>
        ''' Show results for date and double
        ''' </summary>
        Private Sub Demo()
            DateTimePicker1.CustomFormat = DateTimeFormatInfo.CurrentInfo.FullDateTimePattern
            TextBox1.Text = DateTimePicker1.Value.ToString
            Dim value As Double = 123.456789
            TextBox1.Text = value.ToString("c2")
            TextBox2.Text = String.Format("{0:c2}", value)
        End Sub
        Private Sub cmdRestore_Click(sender As Object, e As EventArgs) Handles cmdRestore.Click
            Application.CurrentCulture = New CultureInfo(OriginalCultureName)
            cboCultures.SelectedIndex = OriginalCultureIndex
            cmdChange.PerformClick()
            Demo()
        End Sub
    End Class
    Last edited by luckydead; Sep 23rd, 2022 at 05:45 AM.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,733

    Re: VB.net change system locale

    Is there a special reason for changing to locale/regional settings from within your application?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2017
    Posts
    199

    Re: VB.net change system locale

    Quote Originally Posted by Arnoutdv View Post
    Is there a special reason for changing to locale/regional settings from within your application?
    yes, i need to create a tool that will configurate all new created vps servers to work with specific software

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB.net change system locale

    The software should be able to cope with whatever regional settings etc are in use.

    If it is software you have written, tell us what issues you are having and we can tell you how to fix them (eg: for issues with inputting numbers, use a NumericUpDown [with or without buttons] as it deals with regional settings automatically).

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2017
    Posts
    199

    Re: VB.net change system locale

    the problem is that the specific software comes from external company from Japan.
    The software requires system locale to be set to Japan to work correct.
    And this way i want to make an tool that with a few clicks they can setup everything on each new vps server they created by IT.

    One step is to set the locate option to Japan, thats why i created this thread to make best method to do it.
    The other stuff is related to edit configuration files install path and others

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB.net change system locale

    In that case you will probably need to use an API, and a quick search found this:
    https://learn.microsoft.com/en-us/wi...setlocaleinfoa

    That page doesn't include any code you can use from .Net (search for that), but it does have some useful info.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width