如何在 VB Form 上顯示 UNICODE

VB相關技術
回覆文章
頭像
tim
文章: 1379
註冊時間: 2008年 11月 26日, 00:49

如何在 VB Form 上顯示 UNICODE

文章 tim »

請參考: http://support.microsoft.com/default.as ... bContent=1
Step-by-Step Guide to Build Sample
Install the Chinese language package on your Windows NT computer. See the REFERENCES section below for installation instructions. The MingLiu font will be installed automatically during this step. You can also install other language packages if you want to use other UNICODE language support.
Create a standard EXE project. form1 is created by default.
Select Components from the Project menu and check Microsoft forms 2.0 Object Library. Several new controls are added to the toolbox, including UNICODE versions of the text box, label, and so forth.
Add a forms 2.0 TextBox to form1 and keep its default name: TextBox1. Set the font of the text box to be MingLiu.
Add two CommandButtons to form1.
Add the following code to the code window of form1: Private Sub Command1_Click()
' create a Unicode text file with Chinese character
' Dan1 and English character D.
Dim a(0 To 5) As Byte
a(0) = &HFF
a(1) = &HFE
a(2) = &H39
a(3) = &H4E
a(4) = &H44
a(5) = &H0
Open "unicode.txt" For Binary As #1
Put #1, , a
Close #1
End Sub

Private Sub Command2_Click()
Dim txtline As String

' you may need to change the path of the file
Open "unicode.txt" For Binary As #1

txtline = InputB(2, #1) ' always FF FE, skip them
txtline = InputB(4, #1)

Close #1

TextBox1.Text = txtline ' display the string
End Sub
Note that the UNICODE text file always begins with the Bytes FF FE, which is why you need to skip these two bytes. Also note that to read UNICODE strings from a file, the file needs to be opened as binary and read using InputB.
Run the application. Click Command1 to create the Unicode text file.
Click Command2. The Chinese character Dan1 and the English character D are displayed correctly in the text box. You can also check the unicode.txt file by using notepad with MingLiu font.
多多留言, 整理文章, 把經驗累積下來.....
回覆文章