这是个一段英文打字的代码.可我不知道怎么样才能实现中文打字的效果.哪位哥哥姐姐知道教教我啊.谢谢.我的QQ543958475 知道的请加我QQ教我好吗?谢谢了 Dim lbsource(5) As Label '文字提示内容 Dim lbinput(5) As Label '文字录入内容 Dim csource(300) As Char Dim cinput(300) As Char Dim str As String Dim icorrect, inum, isecond As Integer Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lbsource(1) = Label1 lbsource(2) = Label3 lbsource(3) = Label5 lbsource(4) = Label7 lbsource(5) = Label9 lbinput(1) = Label2 lbinput(2) = Label4 lbinput(3) = Label6 lbinput(4) = Label8 lbinput(5) = Label10 Dim i As Integer For i = 1 To 5 lbsource(i).Visible = False lbinput(i).Visible = False Next Lbstart.Visible = False End Sub Sub openrnd() ReDim csource(300) Dim i As Integer For i = 1 To 300 If i Mod 6 = 0 Then csource(i) = " " Else csource(i) = Chr(Int(Rnd() * 26 + 97)) End If lbsource((i - 1) \ 60 + 1).Text = lbsource((i - 1) \ 60 + 1).Text & csource(i) Next End Sub
Private Sub ToolBar1_ButtonClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick Select Case ToolBar1.Buttons.IndexOf(e.Button) Case 0 Lbstart.Visible = True Lbstart.Focus() Dim i As Integer For i = 1 To 5 lbsource(i).Visible = True lbsource(i).Text = "" lbinput(i).Visible = True lbinput(i).Text = "" Next openrnd() Case 1 Lbstart.Visible = True Dim j As Integer For j = 1 To 5 lbsource(j).Visible = True lbsource(j).Text = "" lbinput(j).Visible = True lbinput(j).Text = "" Next opentxt() End Select End Sub
Sub opentxt() ReDim csource(300) OpenFileDialog1.Filter = "文本文件(*.txt)|*.txt" If OpenFileDialog1.ShowDialog = DialogResult.OK Then FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) Do Until EOF(1) str = str & LineInput(1) If str.Length > 300 Then Exit Do End If Loop Do Until str.Length > 300 str = str & str Loop FileClose(1) csource = str.Substring(0, 300).ToCharArray Dim i As Integer For i = 1 To 300 lbsource((i - 1) \ 60 + 1).Text = lbsource((i - 1) \ 60 + 1).Text & csource(i - 1) Next End If Lbstart.Focus() End Sub
Private Sub Lbstart_keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Lbstart.KeyPress If e.KeyChar = Chr(13) Then Lbstart.Visible = False lbpreformat.Visible = False Panel1.Focus() Timer1.Enabled = True End If
End Sub
Private Sub Panel1_keypress(ByVal sender As Object, ByVal e As System.windows.Forms.KeyPressEventArgs) Handles Panel1.KeyPress Static i As Integer = 1 If i < 301 Then If e.KeyChar = Chr(13) Then cinput(i) = " " Else cinput(i) = e.KeyChar End If lbinput((i - 1) \ 60 + 1).Text = lbinput((i - 1) \ 60 + 1).Text & cinput(i)
If cinput(i) = csource(i) Then icorrect = icorrect + 1 End If i = i + 1 inum = inum + 1 End If If inum = 300 Then Timer1.Enabled = False End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick isecond = isecond + 1 lbpreformat.Visible = True lbpreformat.Text = "正确率:" & icorrect & "/" & inum & "你用了" & isecond & "秒" End Sub End Class