更新:2007 年 11 月
變更目前的執行緒在進行字串管理和字串格式化時,所使用的文化特性。
' Usage My.Application.ChangeCulture(cultureName) ' Declaration Public Sub ChangeCulture( _ ByVal cultureName As String _ )
參數
- cultureName
String。字串形式的文化特性名稱。如需可用名稱的清單,請參閱 CultureInfo。
例外狀況
下列條件可能造成例外狀況:
cultureName 引數為 Nothing (ArgumentNullException)。
cultureName 引數不是有效的文化特性名稱 (ArgumentException)。
備註
My.Application.ChangeCulture 方法會變更目前執行緒的 CurrentCulture 屬性 (Property)。在該執行緒上執行任何計算時,CurrentCulture 會決定日期、時間、貨幣、數字、文字排列順序、字串比較和大小寫的預設格式。
若要擷取目前的文化特性,您可以使用 My.Application.Culture 屬性或 CurrentCulture 屬性。
CurrentCulture 設定和語言設定不同。它只有與地區標準設定的相關資料。因此,CurrentCulture 屬性只可以設定為特定文化特性或 InvariantCulture。
使用 My.Application.ChangeUICulture 方法,變更目前的執行緒在擷取文化特性特有的資源時所使用的文化特性。
安全性注意事項: |
|---|
My.Application.ChangeCulture 方法需要已設定 ControlThread 的 SecurityPermission。操作執行緒是危險的,因為安全狀態與其有關聯。因此,這個使用權限應該只在必要時才會指定給可靠的程式碼。您不可以在非完全信任程式碼中變更執行緒的文化特性。 |
範例
這會示範變更文化特性時,如何變更日期的字串表示。
Private Sub TestChangeCulture()
' Store the current culture.
Dim currentculture As String = My.Application.Culture.Name
MsgBox("Current culture is " & currentculture)
Dim jan1 As New Date(2005, 1, 1, 15, 15, 15)
My.Application.ChangeCulture("en-US")
MsgBox("Date represented in en-US culture: " & jan1)
' 1/1/2005 3:15:15 PM
My.Application.ChangeCulture("")
MsgBox("Date represented in invariant culture" & jan1)
' 01/01/2005 15:15:15
' Restore the culture.
My.Application.ChangeCulture(currentculture)
End Sub
需求
命名空間:Microsoft.VisualBasic.ApplicationServices
類別:WindowsFormsApplicationBase,ApplicationBase
組件:Visual Basic 執行階段程式庫 (在 Microsoft.VisualBasic.dll 中)
依專案類型的可用性
專案類型 |
是否可用 |
|---|---|
Windows 應用程式 |
是 |
類別庫 |
是 |
主控台應用程式 |
是 |
Windows 控制項程式庫 |
是 |
Web 控制項程式庫 |
否 |
Windows 服務 |
是 |
網站 |
否 |
使用權限
下列使用權限可能為必要:
使用權限 |
描述 |
|---|---|
描述套用至程式碼的一組安全性權限。關聯的列舉型別:ControlThread。 |
安全性注意事項: