‘文本框选中显示‘TextBox1.SelectAll()选择所有文本1 Private Sub TextBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick 2 Dim start As Integer = TextBox1.SelectionStart ‘光标开始位置索引 3 Dim SelectValue As String = TextBox1.SelectedText ‘选中文本的值 4 Dim length As Integer = TextBox1.SelectedText.Trim.Length ‘选中文本的长度 5 If length > 0 Then 6 TextBox1.Select(start, length) ‘选中文本从光标到指定长度 7 End If 8 End Sub
‘选中文本后右键弹出菜单栏 1 Private Sub TextBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown 2 3 If TextBox1.SelectedText.Trim.Length > 0 Then 4 If e.Button = Windows.Forms.MouseButtons.Right Then 5 TextBox1.Enabled = False 6 TextBox1.ContextMenuStrip = ContextMenuStrip1 7 TextBox1.Enabled = True 8 End If 9 End If 10 End Sub
时间: 2024-10-28 19:40:29