Thread.CurrentUICulture プロパティ

定義

実行時にカルチャ固有のリソースを検索するためにリソース マネージャーで使用される、現在のカルチャを取得または設定します。

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

プロパティ値

現在のカルチャを表すオブジェクト。

例外

プロパティが null に設定されています。

プロパティが、リソース ファイルの検索に使用できないカルチャ名に設定されています。 リソース ファイル名に使用できるのは、文字、数字、ハイフン、またはアンダースコアのみです。

.NET Core と .NET 5 以降のみ: 別のスレッドからのスレッドのカルチャの読み取りまたは書き込みはサポートされていません。

次の例では、現在のスレッドの UI カルチャの言語がフランス語かどうかを判断します。 そうでない場合は、現在のスレッドの UI カルチャを英語 (米国) に設定します。

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]

次のコード例は、Windows フォームのユーザー インターフェイスが、コントロール パネルに設定されているカルチャに表示できるようにするスレッドステートメントを示しています。 追加のコードが必要です。

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

注釈

UI カルチャは、アプリケーションがユーザーの入力と出力をサポートするために必要なリソースを指定します。既定では、オペレーティング システムのカルチャと同じです。 CultureInfoカルチャ名と識別子、不変、中立、および特定のカルチャの違い、カルチャ情報がスレッドとアプリケーション ドメインに与える影響について学習するには、 クラスを参照してください。 スレッドの既定の CultureInfo.CurrentUICulture UI カルチャがどのように決定されるかについては、 プロパティを参照してください。

重要

プロパティは CurrentUICulture 、現在のスレッド以外のスレッドで使用すると確実に機能しません。 .NET Frameworkでは、 プロパティの読み取りは信頼できますが、現在のスレッド以外のスレッドに設定することはできません。 .NET Core では、 InvalidOperationException スレッドが別のスレッドで プロパティの読み取りまたは書き込 CurrentUICulture みを試みると、 がスローされます。 プロパティを使用して、現在の CultureInfo.CurrentUICulture カルチャを取得して設定することをお勧めします。

このプロパティによって返される は CultureInfo 、ニュートラル カルチャにすることができます。 ニュートラル カルチャは、 などのString.Format(IFormatProvider, String, Object[])DateTime.ToString(String, IFormatProvider)Convert.ToString(Char, IFormatProvider)書式設定メソッドでは使用しないでください。 メソッドを CultureInfo.CreateSpecificCulture 使用して特定のカルチャを取得するか、 プロパティを使用します CurrentCulture

適用対象