Redigera

Dela via


ApplicationBase.ChangeCulture(String) Method

Definition

Changes the culture used by the current thread for string manipulation and for string formatting.

public:
 void ChangeCulture(System::String ^ cultureName);
public void ChangeCulture (string cultureName);
member this.ChangeCulture : string -> unit
Public Sub ChangeCulture (cultureName As String)

Parameters

cultureName
String

String. Name of the culture as a string. For a list of possible names, see CultureInfo.

Exceptions

cultureName is Nothing.

cultureName is not a valid culture name.

Examples

This example demonstrates how changing the culture changes the string representation of dates.

Private Sub TestChangeCulture()
    ' Store the current culture.
    Dim currentculture As String = My.Application.Culture.Name
    MsgBox("Current culture is " & currentculture)

    Dim jan1 As New Date(2005, 1, 1, 15, 15, 15)

    My.Application.ChangeCulture("en-US")
    MsgBox("Date represented in en-US culture: " & jan1)
    ' 1/1/2005 3:15:15 PM

    My.Application.ChangeCulture("")
    MsgBox("Date represented in invariant culture" & jan1)
    ' 01/01/2005 15:15:15

    ' Restore the culture.
    My.Application.ChangeCulture(currentculture)
End Sub

Remarks

The My.Application.ChangeCulture method changes the current thread's CurrentCulture property. CurrentCulture determines the default formats for dates, times, currency, numbers, sorting order of text, string comparisons, and casing for all computations on that thread.

To retrieve the current culture, you can use the Culture property or the CurrentCulture property.

The CurrentCulture setting is different from a language setting. It contains only data related to the standard settings for a geographical region. Therefore, the CurrentCulture property can only be set to a specific culture or to the InvariantCulture.

Use the My.Application.ChangeUICulture method to change the culture that the current thread uses for retrieving culture-specific resources.

Availability by Project Type

Project type Available
Windows Forms Application Yes
Class Library Yes
Console Application Yes
Windows Forms Control Library Yes
Web Control Library No
Windows Service Yes
Web Site No

Applies to

See also