闂傚倷娴囬妴鈧柛瀣崌閺岀喖顢涘⿰鍐炬毉濡炪們鍎婚幏锟� (0) +1 闂備浇宕垫慨宥咁吋閸℃浼� (0) +1 闂傚倸鍊搁オ瀛樼閻戣棄绠柨鐕傛嫹 (0) +1
闂傚倷娴囬妴鈧柛瀣崌閺岀喖顢涘⿰鍐炬毉濡炪們鍎查崹鍧楀蓟閻旇 鍋撳☉娅亝鎱ㄩ崶褉鏀芥い鏇炴鐎氾拷闂傚倷绀侀幖顐ゆ偖椤愶箑纾块柛鎰嚋閼板潡鏌涘☉娆愮稇缂備讲鏅犻弻鐔碱敍濠婂喚鏆銈冨劵閹凤拷>>

正在阅读:让你的VB程序支持多国语言的切换让你的VB程序支持多国语言的切换

2004-10-10 15:07 出处:CSDN 作者:tonylk 责任编辑:linjixiong

  以前做过一个vb的小项目,客户需要软件同时能够支持中文和英文,为此写了一个自动语言切换的模块来用,不敢独享,拿来给大家参考一下,如果你有什么改进也可以写信给我。。mailto:tonyki@citiz.net



  模块 MdlLanMgr.bas :
  Attribute VB_Name = "ModuleLanMgr"
  Option Explicit

  Private Declare Function GetPrivateProfileString& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String)

  Private LanguageFileName As String

  '选择语言

  Public Sub SelectLanguage(LanName As String)
  On Error Resume Next
  
  Select Case LanName    '根据用户选择的语言的名称,分别读取不同的语言文件
  Case "English":
  LanguageFileName = AddSplash(App.Path) & "English.Lan"
  Case "Chinese(Simplify)":
  LanguageFileName = AddSplash(App.Path) & "ChineseS.Lan"
  Case "Chinese(Traditional)":
  LanguageFileName = AddSplash(App.Path) & "ChineseT.Lan"
  Case Else:
  LanguageFileName = ""
  End Select
  End Sub

  '翻译文字

  Public Function TranslateStr(sSection As String, sKey As String, sDefVal As String) As String
  Dim sValue As String * 128
  Dim N As Long
  
  On Error Resume Next
  
  TranslateStr = sDefVal
  If Not FileExists(LanguageFileName) Then
  Exit Function
  End If
  N = GetPrivateProfileString(sSection, sKey, sDefVal, sValue, 127, LanguageFileName)
  If N > 0 Then
  TranslateStr = Left(sValue, N)
  End If
  End Function

  '自动转换Form上的一些基本控件(也可自行扩展,目前支持CommandButton,Label,OptionButton,CheckButton)

  Public Sub TranslateForm(Frm As Form)
  Dim I As Long
  
  On Error Resume Next
  
  Frm.Caption = TranslateStr(Frm.Name, "Caption", Frm.Caption)
  For I = 0 To Frm.Controls.Count - 1
  If (TypeOf Frm.Controls(I) Is CommandButton) Or (TypeOf Frm.Controls(I) Is Label) _
  Or (TypeOf Frm.Controls(I) Is OptionButton) Or (TypeOf Frm.Controls(I) Is CheckBox) Then
  Frm.Controls(I).Caption = TranslateStr(Frm.Name, Frm.Controls(I).Name, Frm.Controls(I).Caption)
  End If
  Next I
  End Sub


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品
闂傚倷绀佺紞濠傖缚瑜旈、鏍幢濡炵粯鏁犻梺閫炲苯澧撮柟顔款潐閹峰懘宕ㄦ繝鍌欐樊婵犵妲呴崑鎾诲箯閿燂拷闂傚倷鐒﹂幃鍫曞磿閹惰棄纾绘繛鎴欏灩閺勩儵鎮橀悙鏉垮珟濞存粍绮撻弻娑㈩敃閿濆棛顦ラ梺鍛婃閹凤拷