Thread.CurrentUICulture 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
Resource Manager에서 런타임에 문화권별 리소스를 조회하는 데 사용하는 현재 문화권을 가져오거나 설정합니다.
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 Forms의 사용자 인터페이스를 허용 하는 스레딩 문을 보여 줍니다. 추가 코드가 필요합니다.
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 려고 하면 throw됩니다. 속성을 사용하여 CultureInfo.CurrentUICulture 현재 문화권을 검색하고 설정하는 것이 좋습니다.
이 속성에서 반환된 CultureInfo 문화권은 중립 문화권일 수 있습니다. 중립 문화권은 형식 지정 메서드(예: String.Format(IFormatProvider, String, Object[]), DateTime.ToString(String, IFormatProvider)및 Convert.ToString(Char, IFormatProvider))와 함께 사용하면 안 됩니다. 메서드를 CultureInfo.CreateSpecificCulture 사용하여 특정 문화권을 얻거나 속성을 사용합니다 CurrentCulture .