Thread.CurrentUICulture Thread.CurrentUICulture Thread.CurrentUICulture Thread.CurrentUICulture Property

Definición

Obtiene o establece la referencia cultural actual utilizada por el administrador de recursos para buscar recursos específicos de la referencia cultural en tiempo de ejecución.Gets or sets the current culture used by the Resource Manager to look up culture-specific resources at run time.

public:
 property System::Globalization::CultureInfo ^ CurrentUICulture { System::Globalization::CultureInfo ^ get(); void set(System::Globalization::CultureInfo ^ value); };
public System.Globalization.CultureInfo CurrentUICulture { get; set; }
member this.CurrentUICulture : System.Globalization.CultureInfo with get, set
Public Property CurrentUICulture As CultureInfo

Valor de propiedad

Objeto que representa la referencia cultural actual.An object that represents the current culture.

Excepciones

La propiedad se establece en null.The property is set to null.

La propiedad se establece en un nombre de referencia cultural que no se puede usar para buscar un archivo de recursos.The property is set to a culture name that cannot be used to locate a resource file. Los nombres de archivo de recursos deben incluir solo letras, números, guiones o caracteres de subrayado.Resource filenames must include only letters, numbers, hyphens or underscores.

Solo .NET Core: no se admite la lectura o escritura de la referencia cultural de un subproceso desde otro subproceso..NET Core only: Reading or writing the culture of a thread from another thread is not supported.

Ejemplos

En el ejemplo siguiente se determina si el idioma de la referencia cultural de la interfaz de usuario del subproceso actual es francés.The following example determines whether the language of the current thread's UI culture is French. Si no es así, establece la referencia cultural de la interfaz de usuario del subproceso actual en inglés (Estados Unidos).If it is not, it sets the UI culture of the current thread to English (United States).

using System;
using System.Globalization;
using System.Threading;

public class Example
{
   public static void Main()
   {
      // Change the current culture if the language is not French.
      CultureInfo current = Thread.CurrentThread.CurrentUICulture;
      if (current.TwoLetterISOLanguageName != "fr") {
         CultureInfo newCulture = CultureInfo.CreateSpecificCulture("en-US");
         Thread.CurrentThread.CurrentUICulture = newCulture;
         // Make current UI culture consistent with current culture.
         Thread.CurrentThread.CurrentCulture = newCulture;
      }
      Console.WriteLine("The current UI culture is {0} [{1}]",
                        Thread.CurrentThread.CurrentUICulture.NativeName,
                        Thread.CurrentThread.CurrentUICulture.Name);
      Console.WriteLine("The current culture is {0} [{1}]",
                        Thread.CurrentThread.CurrentUICulture.NativeName,
                        Thread.CurrentThread.CurrentUICulture.Name);
   }
}
// The example displays the following output:
//     The current UI culture is English (United States) [en-US]
//     The current culture is English (United States) [en-US]
Imports System.Globalization
Imports System.Threading

Module Example
   Public Sub Main()
      ' Change the current culture if the language is not French.
      Dim current As CultureInfo = Thread.CurrentThread.CurrentUICulture
      If current.TwoLetterISOLanguageName <> "fr" Then
         Dim newCulture As CultureInfo = CultureInfo.CreateSpecificCulture("en-US")
         Thread.CurrentThread.CurrentUICulture = newCulture
         ' Make current UI culture consistent with current culture.
         Thread.CurrentThread.CurrentCulture = newCulture
      End If
      Console.WriteLine("The current UI culture is {0} [{1}]",
                        Thread.CurrentThread.CurrentUICulture.NativeName,
                        Thread.CurrentThread.CurrentUICulture.Name)
      Console.WriteLine("The current culture is {0} [{1}]",
                        Thread.CurrentThread.CurrentUICulture.NativeName,
                        Thread.CurrentThread.CurrentUICulture.Name)
   End Sub
End Module
' The example displays output like the following:
'     The current UI culture is English (United States) [en-US]
'     The current culture is English (United States) [en-US]

En el ejemplo de código siguiente se muestra la instrucción de subprocesos que permite que la interfaz de usuario de una Windows Forms muestre en la referencia cultural que se establece en el panel de control.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. Se necesita código adicional.Additional code is needed.

#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.
   }
};


int main()
{
   Application::Run( gcnew UICulture );
}
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.
    }

    static void Main()
    {
        Application.Run(new UICulture());
    }
}
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

    Shared Sub Main()
        Application.Run(New UICulture())
    End Sub
End Class

Comentarios

La referencia cultural de la interfaz de usuario especifica los recursos que una aplicación necesita para admitir la entrada y salida del usuario y, de forma predeterminada, es igual que la referencia cultural del sistema operativo.The UI culture specifies the resources an application needs to support user input and output, and by default is the same as the operating system culture. Vea la CultureInfo clase para obtener información sobre los nombres e identificadores de referencia cultural, las diferencias entre las referencias culturales invariables, las neutras y las específicas y la forma en que la información de referencia cultural afecta a los subprocesos y dominios de aplicación.See the CultureInfo class to learn about culture names and identifiers, the differences between invariant, neutral, and specific cultures, and the way culture information affects threads and application domains. Vea la CultureInfo.CurrentUICulture propiedad para obtener información sobre cómo se determina la referencia cultural predeterminada de la interfaz de usuario de un subproceso.See the CultureInfo.CurrentUICulture property to learn how a thread's default UI culture is determined.

Importante

La CurrentUICulture propiedad no funciona de forma confiable cuando se usa con cualquier subproceso que no sea el subproceso actual.The CurrentUICulture property doesn't work reliably when used with any thread other than the current thread. En .NET Framework, la lectura de la propiedad es confiable, aunque no se establece para un subproceso distinto del subproceso actual.In .NET Framework, reading the property is reliable, although setting it for a thread other than the current thread is not. En .net Core, se InvalidOperationException produce una excepción si un subproceso intenta leer o escribir CurrentUICulture la propiedad en un subproceso diferente.On .NET Core, an InvalidOperationException is thrown if a thread attempts to read or write the CurrentUICulture property on a different thread. Se recomienda usar la CultureInfo.CurrentUICulture propiedad para recuperar y establecer la referencia cultural actual.We recommend that you use the CultureInfo.CurrentUICulture property to retrieve and set the current culture.

El CultureInfo devuelto por esta propiedad puede ser una referencia cultural neutra.The CultureInfo returned by this property can be a neutral culture. Las referencias culturales neutras no deben usarse con métodos String.Format(IFormatProvider, String, Object[])de DateTime.ToString(String, IFormatProvider)formato como Convert.ToString(Char, IFormatProvider), y.Neutral cultures should not be used with formatting methods such as String.Format(IFormatProvider, String, Object[]), DateTime.ToString(String, IFormatProvider), and Convert.ToString(Char, IFormatProvider). Use el CultureInfo.CreateSpecificCulture método para obtener una referencia cultural concreta o use la CurrentCulture propiedad.Use the CultureInfo.CreateSpecificCulture method to get a specific culture, or use the CurrentCulture property.

Nota

El CultureInfo.CreateSpecificCulture métodoArgumentException produce para las referencias culturales neutras "ZH-hant" ("ZH-CHT") y "ZH-Hans" ("ZH-CHS").The CultureInfo.CreateSpecificCulture method throws ArgumentException for the neutral cultures "zh-Hant" ("zh-CHT") and "zh-Hans" ("zh-CHS").

Se aplica a