Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

Thread.CurrentUICulture-Eigenschaft

 

Veröffentlicht: Oktober 2016

Ruft die aktuelle Kultur ab, mit deren Hilfe der Ressourcen-Manager zur Laufzeit kulturabhängige Ressourcen sucht, oder legt diese fest.

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

public CultureInfo CurrentUICulture {
	get;
	[HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)]
	set;
}

Eigenschaftswert

Type: System.Globalization.CultureInfo

Ein Objekt, das die aktuelle Kultur darstellt.

Exception Condition
ArgumentNullException

Die Eigenschaft ist auf null festgelegt.

ArgumentException

Die Eigenschaft ist auf einen Kulturnamen festgelegt, der nicht zum Suchen einer Ressourcendatei verwendet werden kann. Ressourcendateinamen dürfen nur Buchstaben, Zahlen, Bindestriche oder Unterstriche enthalten.

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. See the T:System.Globalization.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. See the P:System.Globalization.CultureInfo.CurrentUICulture property to learn how a thread's default UI culture is determined.

The T:System.Globalization.CultureInfo returned by this property can be a neutral culture. Neutral cultures should not be used with formatting methods such as M:System.String.Format(System.IFormatProvider,System.String,System.Object[]), M:System.DateTime.ToString(System.String,System.IFormatProvider), and M:System.Convert.ToString(System.Char,System.IFormatProvider). Use the M:System.Globalization.CultureInfo.CreateSpecificCulture(System.String) method to get a specific culture, or use the P:System.Threading.Thread.CurrentCulture property.

System_CAPS_noteHinweis

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

The following example determines whether the language of the current thread's UI culture is French. 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]

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.

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());
    }
}

.NET Framework
Verfügbar seit 1.1
Portierbare Klassenbibliothek
Unterstützt in: portierbare .NET-Plattformen
Silverlight
Verfügbar seit 2.0
Windows Phone Silverlight
Verfügbar seit 7.0
Zurück zum Anfang
Anzeigen: