Export (0) Print
Expand All

ApplicationBase.ChangeCulture Method

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

Namespace:  Microsoft.VisualBasic.ApplicationServices
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

[HostProtectionAttribute(SecurityAction.LinkDemand, Resources = HostProtectionResource.ExternalProcessMgmt)]
public void ChangeCulture(
	string cultureName
)

Parameters

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

ExceptionCondition
ArgumentNullException

cultureName is Nothing.

ArgumentException

cultureName is not a valid culture name.

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.

Security noteSecurity Note

The My.Application.ChangeCulture method requires a SecurityPermission with the ControlThread set. Manipulating threads is dangerous because of the security state associated with threads. Therefore, this permission should be given only as necessary to trustworthy code. You cannot change a thread's culture in semi-trusted code.

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

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Resources. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

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


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2015 Microsoft