.NET Framework Class Library
Thread..::.CurrentUICulture Property

Updated: November 2007

Gets or sets the current culture used by the Resource Manager to look up culture-specific resources at run time.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

Visual Basic (Declaration)
Public Property CurrentUICulture As CultureInfo
Visual Basic (Usage)
Dim instance As Thread
Dim value As CultureInfo

value = instance.CurrentUICulture

instance.CurrentUICulture = value
C#
public CultureInfo CurrentUICulture { get; set; }
Visual C++
public:
property CultureInfo^ CurrentUICulture {
    CultureInfo^ get ();
    void set (CultureInfo^ value);
}
J#
/** @property */
public CultureInfo get_CurrentUICulture()
/** @property */
public  void set_CurrentUICulture(CultureInfo value)
JScript
public function get CurrentUICulture () : CultureInfo
public function set CurrentUICulture (value : CultureInfo)

Property Value

Type: System.Globalization..::.CultureInfo

A CultureInfo representing the current culture.

ExceptionCondition
ArgumentNullException

The property is set to nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentException

The property is set to a culture name that cannot be used to locate a resource file. Resource filenames must include only letters, numbers, hyphens or underscores.

The CultureInfo returned by this property can be a neutral culture. Neutral cultures should not be used with formatting methods such as String..::.Format(IFormatProvider, String, array<Object>[]()[]), DateTime..::.ToString(String, IFormatProvider), and Convert..::.ToString(Char, IFormatProvider). Use the CultureInfo..::.CreateSpecificCulture method to get a specific culture, or use the CurrentCulture property. For more information, see Formatting for Different Cultures.

Note:

The CultureInfo..::.CreateSpecificCulture method throws ArgumentException for the neutral cultures "zh-Hant" ("zh-CHT") and "zh-Hans" ("zh-CHS").

The following code example shows the threading statement that allows the user interface of a Windows Forms to display in the culture that is set in Control Panel. Additional code is needed.

Visual Basic
' Compile with option t:winexe /r:System.dll,System.Windows.Forms.dll.

Option Explicit
Option Strict

Imports System
Imports System.Threading
Imports System.Windows.Forms

Public Class UICulture
    Inherits Form

    Sub New()

        ' Set the user interface to display in the
        ' same culture as that set in Control Panel.
        Thread.CurrentThread.CurrentUICulture = _
            Thread.CurrentThread.CurrentCulture

        ' Add additional code.
    End Sub

    <STAThreadAttribute> Shared Sub Main()
        Application.Run(New UICulture())
    End Sub

End Class

C#
// Compile with option /t:winexe.

using System;
using System.Threading;
using System.Windows.Forms;

class UICulture : Form
{
    public UICulture()
    {
        // Set the user interface to display in the
        // same culture as that set in Control Panel.
        Thread.CurrentThread.CurrentUICulture = 
            Thread.CurrentThread.CurrentCulture;

        // Add additional code.
    }

    [STAThreadAttribute]
    static void Main()
    {
        Application.Run(new UICulture());
    }
}

Visual C++
#using <system.dll>
#using <System.Drawing.dll>
#using <system.windows.forms.dll>

using namespace System;
using namespace System::Threading;
using namespace System::Windows::Forms;
ref class UICulture: public Form
{
public:
   UICulture()
   {

      // Set the user interface to display in the
      // same culture as that set in Control Panel.
      Thread::CurrentThread->CurrentUICulture = Thread::CurrentThread->CurrentCulture;

      // Add additional code.
   }

};


[STAThreadAttribute]
int main()
{
   Application::Run( gcnew UICulture );
}


J#
// Compile with option /t:winexe.
import System.*;
import System.Threading.*;
import System.Threading.Thread;
import System.Windows.Forms.*;

class UICulture extends Form
{
    public UICulture()
    {
        // Set the user interface to display in the
        // same culture as that set in Control Panel.
        Thread.get_CurrentThread().set_CurrentUICulture(
            Thread.get_CurrentThread().get_CurrentCulture());
        // Add additional code.
    } //UICulture


    /** @attribute STAThreadAttribute()
     */
    public static void main(String[] args)
    {
        Application.Run(new UICulture());
    } //main
} //UICulture

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Page view tracker