这里所说的区域设置,应该是 OS 的区域设置,换句话说,是中文环境还是其他语言的环境。
上一篇解释了如何将窗体控件的 Text (按照 VFP 习惯的说法,就是控件的 Caption)实现多语言的方法,今天来看一下控件根据不同的区域设置显示不同语言文件内容的方法。
首先准备两个RTF文件。一个英文的,一个中文的。假设,它们分别是 Warning.rtf 和 Warning_CN.rtf。
打开 VS IDE,创建基于模板的项目,如下图所示:
我将项目命名为 Demo
更改项目属性,将所使用的方言更改为 Visual FoxPro,并更改“语言”和“方言”中的选项以“适配”所选方言。
双击打开 form1.prg,进入窗体设计模式,从工具箱中拉一个 RichTextBox 控件到表单,并命名为 rtfWarning 。
在项目中添加“现有项”--事先准备好的RTF文件。
然后在项目属性的资源中,也添加这两个文件。
窗体代码如下:
Using System
Using System.Collections.Generic
Using System.ComponentModel
Using System.Data
Using System.Drawing
Using System.Linq
Using System.Text
Using System.IO
Using System.Threading
Using System.Threading.Tasks
Using System.Windows.Forms
Begin Namespace demo
Public Partial Class Form1 ;
Inherit System.Windows.Forms.Form
Public Constructor() Strict//Form1
InitializeComponent()
Return
End Constructor
Private Method Form1_Load(sender As System.Object, e As System.EventArgs) As Void Strict
This.LoadLocalizedRTF()
Return
End Method
Private Method LoadLocalizedRTF() As Void
Local rtfContent = ""
Local cultureName = Thread.CurrentThread.CurrentCulture.Name
If cultureName = "zh-CN"
rtfContent = demo.Properties.Resources.Warning_CN
Else
rtfContent = demo.Properties.Resources.Warning
End
This.rtfWarning.Rtf = rtfContent
Return
End Class
End Namespace
OVER!
Follow me,延续自己的技术生命!