16,552
社区成员
发帖
与我相关
我的任务
分享
Private Sub FrmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strDefuLang As String
strDefuLang = System.Configuration.ConfigurationManager.AppSettings("Language").ToString
LoadLanguage(Me, strDefuLang)
Dim uiCulture As CultureInfo = System.Threading.Thread.CurrentThread.CurrentUICulture
MsgBox("name:" + uiCulture.Name + " , display name:" + uiCulture.DisplayName)
End Sub
Public Sub LoadLanguage(ByVal aForm As Form, ByVal vLang As String)
If Not aForm Is Nothing Then
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(vLang)
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(aForm.GetType())
resources.ApplyResources(aForm, "$this")
LoadingControls(aForm, resources)
End If
End Sub
Private Shared Sub LoadingControls(ByVal aControl As Control, ByVal aResources As System.ComponentModel.ComponentResourceManager)
If TypeOf aControl Is MenuStrip Then
'将资源与控件对应
aResources.ApplyResources(aControl, aControl.Name)
Dim menu As MenuStrip = CType(aControl, MenuStrip)
If menu.Items.Count > 0 Then
Dim item As ToolStripMenuItem
For Each item In menu.Items
'遍历菜单
Loading(item, aResources)
Next
End If
End If
Dim ctrl As Control
For Each ctrl In aControl.Controls
aResources.ApplyResources(ctrl, ctrl.Name)
LoadingControls(ctrl, aResources)
Next
End Sub
Private Shared Sub Loading(ByVal aItem As ToolStripMenuItem, ByVal aResources As System.ComponentModel.ComponentResourceManager)
If TypeOf aItem Is ToolStripMenuItem Then
aResources.ApplyResources(aItem, aItem.Name)
If aItem.DropDownItems.Count > 0 Then
Dim item As ToolStripMenuItem
For Each item In aItem.DropDownItems
Loading(item, aResources)
Next
End If
End If
End Sub