C#文本选中及ContextMenuStrip菜单使用

'文本框选中显示
'TextBox1.SelectAll()选择所有文本
'textBox1.Text.Insert(start,strInsertText)指定位置添加文本
1 Private Sub TextBox1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick
Dim start As Integer = TextBox1.SelectionStart '光标开始位置索引
Dim SelectValue As String = TextBox1.SelectedText '选中文本的值
Dim length As Integer = TextBox1.SelectedText.Trim.Length '选中文本的长度
If length > Then
TextBox1.Select(start, length) '选中文本从光标到指定长度
End If
End Sub
'选中文本后右键弹出菜单栏
1 Private Sub TextBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown If TextBox1.SelectedText.Trim.Length > Then
If e.Button = Windows.Forms.MouseButtons.Right Then
TextBox1.Enabled = False
TextBox1.ContextMenuStrip = ContextMenuStrip1
TextBox1.Enabled = True
End If
End If
End Sub
上一篇:TCP 之 RST 原因分析


下一篇:记一次修复被篡改的IE首页