VB 如何自动选择文本框里面特定位置的字符?
来源:百度知道 编辑:UC知道 时间:2024/05/22 18:43:43
文本框有 表示选择开始。长度的属性,
好像是 selStart 和selTextLength,这两个属性都是可读写的
再结合字符串查找函数就可以做到了。
////////
给点分啊,我帮你写了^_^
vs2005 +vb.net 测试通过,
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = "我爱编程-百度知道"
End Sub
Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Click
Dim curindex As Integer = TextBox1.SelectionStart
Dim ganindex As Integer = TextBox1.Text.IndexOf("-")
If curindex < ganindex Then
TextBox1.SelectionStart = 0
TextBox1.SelectionLength = ganindex
Else
TextBox1.SelectionStart = ganindex + 1
TextBox1.SelectionLength = TextBox1.Text.Length - ganindex
End If
End Sub
End Class
如果