同一个exe,不同电脑上执行,设置 CurrentUICulture的结果却不同

JERRY_LIU JERRY_LIU 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
设置软件的多国语言界面,在开发电脑上测试OK,en时显示英文,zh-cn时显示中文简体

但是把Exe复制到客户机上,设置zh-cn还是显示英文,用System.Threading.Thread.CurrentThread.CurrentUICulture获取当前值,也是zh-cn,就是界面文字还是英文。

这是什么情况?
代码如下,form load:

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


loadLanguage:

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
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
JERRY_LIU
VB 16,718 成员 110,520 内容