c# textbox.text="AAA;BBB;CCCC;EFGDI; " 控件能否根据鼠标点击位置 能够根据分隔符动态获得其指定的一段文本内容 如(1,3 或 5,7 ),并将其置为选中状态? private void button2_Click(object sender, EventArgs e) { this.textBox1.Focus(); this.textBox1.Select(1, 2); } 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 textBox.SelectionStart标示出来当前光标的位置,根据位置判断当前分割的文本内容,然后用Select方法选中即可。 2.0 直接使用 MaskedTextBox 控件就可... 设置参照:this.maskedTextBox1.PromptChar = ' ';this.maskedTextBox1.Mask = "AAA;AAAA;AAAA;AAAA"; 试了下,这样写:private void textBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { //分隔符 string splitSymbol = ";"; //获取当前光标索引 int currentIndex = textBox1.SelectionStart; //如果当前光标所在位置对应字符为分隔符,刚退出 if (currentIndex < textBox1.Text.Length && textBox1.Text[currentIndex].ToString() == splitSymbol) return; int beginIndex;//选中文本起始下标 int endIndex;//选中文本结束下标 beginIndex = textBox1.Text.LastIndexOf(splitSymbol, currentIndex) + 1; endIndex = textBox1.Text.IndexOf(splitSymbol, currentIndex); if (beginIndex < 0) { beginIndex = 0; } if (endIndex < 0) { endIndex = textBox1.Text.Length; } //选中文本 textBox1.Select(beginIndex, endIndex - beginIndex); } } 楼上说的很清啦,使用 //分隔符 string splitSymbol = ";"; //获取当前光标索引 这种方式还是不错的,举一反三! winform窗体传值 调用c++编写的dll,程序报错,高分求解,高手进,急!!!!! 急求一个通讯录 C#中如何让Form逐渐消失 memcpy转换的问题 Microsoft.Web.UI.WebControls中treeview控件问题,求救!!先放20分,结贴再加100!! C#中怎么 将从数据库中选出数值型数据用取整后显示出来?(sqlserver库,把原来的字段/1024/1024后取整,怎么办?) 用GDI+做得自定义实时显示数据控件叠加时的效率问题 请问如何判断对象是否实例化? DEV chartcontrol X轴范围 AD活动目录接口的开发 c#web中的数据集提交?
this.maskedTextBox1.Mask = "AAA;AAAA;AAAA;AAAA";
private void textBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//分隔符
string splitSymbol = ";";
//获取当前光标索引
int currentIndex = textBox1.SelectionStart;
//如果当前光标所在位置对应字符为分隔符,刚退出
if (currentIndex < textBox1.Text.Length && textBox1.Text[currentIndex].ToString() == splitSymbol)
return; int beginIndex;//选中文本起始下标
int endIndex;//选中文本结束下标
beginIndex = textBox1.Text.LastIndexOf(splitSymbol, currentIndex) + 1;
endIndex = textBox1.Text.IndexOf(splitSymbol, currentIndex);
if (beginIndex < 0)
{
beginIndex = 0;
}
if (endIndex < 0)
{
endIndex = textBox1.Text.Length;
}
//选中文本
textBox1.Select(beginIndex, endIndex - beginIndex);
}
}
使用 //分隔符
string splitSymbol = ";";
//获取当前光标索引
这种方式还是不错的,举一反三!