0

我有两个文本框..

我想在 KeyPress 事件期间提取/复制要由用户输入到另一个 TextBox 的所有大写字母。

逻辑:

Private Sub TextBox1_KeyPress()

'If the Character is a Capital Letter Then
'   Copy and Concatenate it to the second TextBox
'End If

End Sub
4

3 回答 3

2

你可以试试这个:

For i = 0 To TextBox1.Text.Length - 1
    Dim c As Char = TextBox1.Text.Chars(i)
    If Char.IsUpper(c) Then
        TextBox2.AppendText(c)
    End If
Next

如果你需要它作为一个函数:

Private Function ExtractUppers(ByVal txt As TextBox) As String
    Dim sExtract As String = ""
    For i = 0 To txt.Text.Length - 1
        Dim c As Char = txt.Text.Chars(i)

        If Char.IsUpper(c) Then
            sExtract = sExtract & c
        End If
    Next

    Return sExtract
End Function

在您的按钮中:

 TextBox2.Text = ExtractUppers(TextBox1)
于 2013-01-10T16:44:00.247 回答
2

已经被朋友解决了!:) 感谢您的回复!

Private Sub TextBox1_TextChange()

      CapitalLetter = Regex.Replace(TextBox1.Text, "[^A-Z]", String.Empty)
      TextBox2.Text = CapitalLetter

End Sub
于 2013-01-10T17:09:10.617 回答
0

也许你可以使用这个技巧:

If letterVar = letterVar.ToUpper() then
    TextBox2.Text &= letterVar
End if
于 2013-01-10T16:53:52.810 回答