110,561
社区成员
发帖
与我相关
我的任务
分享
if (RichTextBox1.Text == "")
{
Return;
}
if (RichTextBox1.Text.Contains(",")==false)
{
RichTextBox1.SelectAll();
return;
}
int i =RichTextBox1.SelectionStart;
int m = i;
int n = i;
While (m > 0 && RichTextBox1.Text.Chars[m] != ",")
{
m--;
}
if (RichTextBox1.Text.Chars[m] == ",")
{ m += 1;}
While (n < RichTextBox1.Text.Length && RichTextBox1.Text.Chars[n] != ",")
{
n++;
}
RichTextBox1.Select(m, n - m);
Private Sub RichTextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.Click
If RichTextBox1.Text = "" Then
Exit Sub
End If
If Not RichTextBox1.Text.Contains(",") Then
RichTextBox1.SelectAll()
Exit Sub
End If
Dim i As Integer = RichTextBox1.SelectionStart
Dim m As Integer = i
Dim n As Integer = i
While m > 0 AndAlso RichTextBox1.Text.Chars(m) <> ","
m -= 1
End While
If RichTextBox1.Text.Chars(m) = "," Then
m += 1
End If
While n < RichTextBox1.Text.Length AndAlso RichTextBox1.Text.Chars(n) <> ","
n += 1
End While
Me.RichTextBox1.Select(m, n - m)
End Sub
private void richTextBox1_Click( object sender, EventArgs e )
{
int start = -1; //开始位置
int end = -1; //结束位置
start = richTextBox1.Text.Substring( 0, richTextBox1.SelectionStart ).LastIndexOf( ',' );
end = richTextBox1.Text.Substring( richTextBox1.SelectionStart ).IndexOf( ',' );
if ( start == -1 )
{
start = 0;
}
else
{
start++; //取逗号后一个位置
}
if ( end == -1 )
{
end = richTextBox1.Text.Length;
}
else
{
end = end + richTextBox1.SelectionStart - 1; //取逗号前一个位置
}
//选择
richTextBox1.Select( start, end - start + 1 );
}