表单的多国语言程序切换范例
时间:2014-07-17 20:15 来源: 我爱IT技术网 作者:山风
今天实验做Form在开启状态下切换语言的代码,如下面两张图。
我所使用的文件读取方式是采用ini的读取方式,并建立两个ini文件,分别为中文test.CHT与英文test.ENG
要实现的效果,当我按中文时,从中文文件读入,当我按英文时,从英文文件读入

程序中通过按钮设定路径,并通过副程序的调用执行文件的读取,范例如下:
- Imports System.Text
- Imports System.Runtime.InteropServices
- Public Class Form1
- Dim pathA As String = ""
- Public Declare Function GetPrivateProfileString Lib "kernel32" _
- Alias "GetPrivateProfileStringA" ( _
- <MarshalAs(UnmanagedType.LPStr)> ByVal lpApplicationName As String, _
- <MarshalAs(UnmanagedType.LPStr)> ByVal lpKeyName As String, _
- <MarshalAs(UnmanagedType.LPStr)> ByVal lpDefault As String, _
- <MarshalAs(UnmanagedType.LPStr)> ByVal lpReturnedString As StringBuilder, _
- ByVal nSize As UInt32, _
- <MarshalAs(UnmanagedType.LPStr)> ByVal lpFileName As String) As UInt32
- Public Declare Function WritePrivateProfileString Lib "kernel32" _
- Alias "WritePrivateProfileStringA" ( _
- <MarshalAs(UnmanagedType.LPStr)> ByVal lpApplicationName As String, _
- <MarshalAs(UnmanagedType.LPStr)> ByVal lpKeyName As String, _
- <MarshalAs(UnmanagedType.LPStr)> ByVal lpReturnedString As StringBuilder, _
- <MarshalAs(UnmanagedType.LPStr)> ByVal lpFileName As String) As UInt32
- Dim sKeyValue As New StringBuilder(1024)
- Dim nSize As UInt32 = Convert.ToUInt32(1024)
- Dim sinifilename As String = Application.StartupPath & pathA '读档档名位置
- Public Sub renew()
- GetPrivateProfileString("City", "City_1", "", sKeyValue, nSize, Application.StartupPath & pathA)
- Label1.Text = sKeyValue.ToString
- GetPrivateProfileString("City", "City_2", "", sKeyValue, nSize, Application.StartupPath & pathA)
- Label2.Text = sKeyValue.ToString
- GetPrivateProfileString("City", "City_3", "", sKeyValue, nSize, Application.StartupPath & pathA)
- Label3.Text = sKeyValue.ToString
- GetPrivateProfileString("City", "City_4", "", sKeyValue, nSize, Application.StartupPath & pathA)
- Label4.Text = sKeyValue.ToString
- GetPrivateProfileString("City", "City_5", "", sKeyValue, nSize, Application.StartupPath & pathA)
- Label5.Text = sKeyValue.ToString
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- pathA = "\\test.CHT"
- Call renew()
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- pathA = "\\test.ENG"
- Call renew()
- End Sub
- End Class
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
