Thread.CurrentUICulture Eigenschap

Definitie

Hiermee haalt u de huidige cultuur op die door de Resource Manager wordt gebruikt om cultuurspecifieke resources tijdens runtime op te zoeken of in te stellen.

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

Waarde van eigenschap

Een object dat de huidige cultuur vertegenwoordigt.

Uitzonderingen

De eigenschap is ingesteld op null.

De eigenschap is ingesteld op een cultuurnaam die niet kan worden gebruikt om een resourcebestand te vinden. Resourcebestandsnamen mogen alleen letters, cijfers, afbreekstreepjes of onderstrepingstekens bevatten.

.NET Core en .NET 5+ alleen: lezen of schrijven van de cultuur van een thread van een andere thread wordt niet ondersteund.

Voorbeelden

In het volgende voorbeeld wordt bepaald of de taal van de ui-cultuur van de huidige thread Frans is. Als dit niet het is, wordt de UI-cultuur van de huidige thread ingesteld op Engels (Verenigde Staten).

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]
open System.Globalization
open System.Threading

// Change the current culture if the language is not French.
let current = Thread.CurrentThread.CurrentUICulture

if current.TwoLetterISOLanguageName <> "fr" then
    let newCulture = CultureInfo.CreateSpecificCulture "en-US"
    Thread.CurrentThread.CurrentUICulture <- newCulture
    // Make current UI culture consistent with current culture.
    Thread.CurrentThread.CurrentCulture <- newCulture

printfn
    $"The current UI culture is {Thread.CurrentThread.CurrentUICulture.NativeName} [{Thread.CurrentThread.CurrentUICulture.Name}]"

printfn
    $"The current culture is {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]

In het volgende codevoorbeeld ziet u de threading-instructie waarmee de gebruikersinterface van een Windows Forms kan worden weergegeven in de cultuur die is ingesteld in Configuratiescherm. Er is extra code nodig.

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());
    }
}
open System.Threading
open System.Windows.Forms

type UICulture() =
    inherit Form()

    do
        // 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.

new UICulture() |> Application.Run
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

Opmerkingen

De UI-cultuur specificeert de resources die een toepassing nodig heeft om gebruikersinvoer en -uitvoer te ondersteunen en is standaard hetzelfde als de cultuur van het besturingssysteem. Zie de CultureInfo klasse voor meer informatie over cultuurnamen en id's, de verschillen tussen invariant, neutraal en specifieke culturen, en de manier waarop cultuurinformatie van invloed is op threads en toepassingsdomeinen. Zie de CultureInfo.CurrentUICulture eigenschap voor meer informatie over hoe de standaard-UI-cultuur van een thread wordt bepaald.

Important

De CurrentUICulture eigenschap werkt niet betrouwbaar wanneer deze wordt gebruikt met een andere thread dan de huidige thread. In .NET Framework is het lezen van de eigenschap betrouwbaar, hoewel het instellen van de eigenschap voor een andere thread dan de huidige thread niet is. Op .NET Core wordt een InvalidOperationException gegenereerd als een thread de eigenschap CurrentUICulture op een andere thread probeert te lezen of te schrijven. U wordt aangeraden de CultureInfo.CurrentUICulture eigenschap te gebruiken om de huidige cultuur op te halen en in te stellen.

De CultureInfo geretourneerde door deze eigenschap kan een neutrale cultuur zijn. Neutrale culturen mogen niet worden gebruikt met opmaakmethoden zoals String.Format(IFormatProvider, String, Object[]), DateTime.ToString(String, IFormatProvider)en Convert.ToString(Char, IFormatProvider). Gebruik de CultureInfo.CreateSpecificCulture methode om een specifieke cultuur op te halen of gebruik de CurrentCulture eigenschap.

Van toepassing op