我是Visual Basic的新手。我想在like
中使用textbox
运算符来更改字符,如果后跟任何其他字符。但它应该在key-up
事件上。
任何人都可以帮助我:我如何使以下代码有效?
Public Class Form1
Dim myString As String
Dim sMatch As Boolean = myString Like "x?"
Private Sub TextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If sMatch = True Then
TextBox1.Text = TextBox1.Text.Replace(myString, "z")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myString = "x"
End Sub
End Class
答案 0 :(得分:0)
试试这个然后问。您的变量myString
从未从TextBox中获取它的值。您只需在x
事件中将其设置为load
。
Public Class Form1
Private Sub TextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If TextBox1.Text Like "x?" Then
TextBox1.Text = TextBox1.Text.Replace(TextBox1.Text, "z")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = "x"
End Sub
End Class