VB.net关于Textbox文本控件全选的小技巧

前端之家收集整理的这篇文章主要介绍了VB.net关于Textbox文本控件全选的小技巧前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

#Region "搜索框的全选"

@H_404_18@ Dim counter As Integer = 0 '点击次数

@H_404_18@ Dim isSelectAll As Boolean = False '是否全选

@H_404_18@ Dim selectPoint As Integer = 0@H_404_18@ '当前光标位置

@H_404_18@ Private Sub TextBox1_Click(ByVal sender As Object,ByVal e As System.EventArgs) Handles TextBox1.Click

@H_404_18@ counter += 1

@H_404_18@ If counter = 1 Then '判断是否首次点击

@H_404_18@ selectPoint = TextBox1.SelectionStart

@H_404_18@ TextBox1.SelectAll()

@H_404_18@ isSelectAll = True

@H_404_18@ ElseIf counter > 1 Then

@H_404_18@ If TextBox1.SelectionLength = 0 Then '判断选择字符的长度是否为0

@H_404_18@ If TextBox1.SelectionStart = selectPoint Then '判断是否点击上次同一位置

@H_404_18@ If isSelectAll = True Then

@H_404_18@ isSelectAll = False

@H_404_18@ Else

@H_404_18@ TextBox1.SelectAll()

@H_404_18@ @H_404_18@isSelectAll = True

@H_404_18@ End If

@H_404_18@ Else

@H_404_18@ If TextBox1.SelectionStart = TextBox1.TextLength AndAlso isSelectAll = False Then '判断光标位置在最末

@H_404_18@ TextBox1.SelectAll()

@H_404_18@ isSelectAll = True

@H_404_18@ Else

@H_404_18@ selectPoint = TextBox1.SelectionStart '不是上次同一位置,则记录当前位置

@H_404_18@ isSelectAll = False

@H_404_18@ End If

@H_404_18@ End If

@H_404_18@ End If

@H_404_18@ End If

@H_404_18@ End Sub

@H_404_18@ Private Sub TextBox1_LostFocus(ByVal sender As Object,ByVal e As System.EventArgs) Handles TextBox1.LostFocus

@H_404_18@ counter = 0

@H_404_18@ End Sub

@H_404_18@ Private Sub TextBox1_DoubleClick(ByVal sender As Object,ByVal e As System.EventArgs) Handles TextBox1.DoubleClick

@H_404_18@ isSelectAll = True

@H_404_18@ End Sub

#End Region

猜你在找的VB相关文章