Thread.CurrentUICulture Propriedade

Definição

Obtém ou define a cultura atual usada pelo Gerenciador de Recursos para procurar recursos específicos da cultura em tempo de execução.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 da propriedade

CultureInfo

Um objeto que representa a cultura atual.An object that represents the current culture.

Exceções

A propriedade é definida como null.The property is set to null.

A propriedade é definida como um nome de cultura não pode ser usado para localizar um arquivo de recurso.The property is set to a culture name that cannot be used to locate a resource file. Nomes de arquivos de recursos devem incluir somente letras, números, hifens ou sublinhados.Resource filenames must include only letters, numbers, hyphens or underscores.

Somente .NET 5+ e .NET Core: não há suporte para leitura ou gravação da cultura de um thread por meio de outro thread..NET 5+ and .NET Core only: Reading or writing the culture of a thread from another thread is not supported.

Exemplos

O exemplo a seguir determina se o idioma da cultura da interface do usuário do thread atual é francês.The following example determines whether the language of the current thread's UI culture is French. Se não estiver, ele definirá a cultura da interface do usuário do thread atual como 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]

O exemplo de código a seguir mostra a declaração de Threading que permite que a interface do usuário de um Windows Forms seja exibida na cultura que está definida no painel de controle.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. O código adicional é necessário.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

Comentários

A cultura da interface do usuário especifica os recursos que um aplicativo precisa para dar suporte à entrada e saída do usuário e, por padrão, é o mesmo que a cultura do sistema operacional.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. Consulte a CultureInfo classe para saber mais sobre nomes de cultura e identificadores, as diferenças entre culturas invariáveis, neutras e específicas e a forma como as informações de cultura afetam threads e domínios de aplicativo.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. Consulte a CultureInfo.CurrentUICulture propriedade para saber como a cultura da interface do usuário padrão de um thread é determinada.See the CultureInfo.CurrentUICulture property to learn how a thread's default UI culture is determined.

Importante

A CurrentUICulture propriedade não funciona de maneira confiável quando usada com qualquer thread que não seja o thread atual.The CurrentUICulture property doesn't work reliably when used with any thread other than the current thread. No .NET Framework, a leitura da propriedade é confiável, embora configurá-la para um thread diferente do thread atual não seja.In .NET Framework, reading the property is reliable, although setting it for a thread other than the current thread is not. No .NET Core, um InvalidOperationException será gerado se um thread tentar ler ou gravar a CurrentUICulture propriedade em um thread diferente.On .NET Core, an InvalidOperationException is thrown if a thread attempts to read or write the CurrentUICulture property on a different thread. Recomendamos que você use a CultureInfo.CurrentUICulture propriedade para recuperar e definir a cultura atual.We recommend that you use the CultureInfo.CurrentUICulture property to retrieve and set the current culture.

O CultureInfo retornado por essa propriedade pode ser uma cultura neutra.The CultureInfo returned by this property can be a neutral culture. Culturas neutras não devem ser usadas com métodos de formatação como String.Format(IFormatProvider, String, Object[]) , DateTime.ToString(String, IFormatProvider) e Convert.ToString(Char, IFormatProvider) .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 o CultureInfo.CreateSpecificCulture método para obter uma cultura específica ou use a CurrentCulture propriedade.Use the CultureInfo.CreateSpecificCulture method to get a specific culture, or use the CurrentCulture property.

Observação

O CultureInfo.CreateSpecificCulture método gera ArgumentException para as culturas neutras "zh-Hant" ("zh-CHT") e "zh-Hans" ("zh-CHS").The CultureInfo.CreateSpecificCulture method throws ArgumentException for the neutral cultures "zh-Hant" ("zh-CHT") and "zh-Hans" ("zh-CHS").

Aplica-se a