我尝试选择已更改的事件但由于文本框本身更改为零而无效,我的selection_changed代码从那里处理。
默认情况下,我不需要将光标位置更改为零。
继承人我的表格看起来像。
一键按MyCode:
private void button3_MouseClick(object sender, MouseEventArgs e)
{
MyTimer.Start();
if (e.Button == MouseButtons.Left)
{
clicked += e.Clicks;
}
switch (clicked % 2)
{
case 1:
{
if (clicked > 1)
{
if (selectionstart < textBox1.Text.Length)
{
string myString = textBox1.Text.ToString();
StringBuilder sb = new StringBuilder();
string part1 = myString.Substring(0, selectionstart);
int length = myString.Length - selectionstart - 1;
string part2 = myString.Substring(selectionstart + 1, length);
sb.Append(part1);
sb.Append("a");
sb.Append(part2);
textBox1.Text = sb.ToString();
break;
}
else
{
string myString = textBox1.Text.ToString();
myString = myString.Substring(0, myString.Length - 1);
textBox1.Text = myString;
textBox1.AppendText("a");
break;
}
}
else
{
if (selectionstart < textBox1.Text.Length)
{
string myString = textBox1.Text.ToString();
StringBuilder sb = new StringBuilder();
string part1 = myString.Substring(0, selectionstart);
int length = myString.Length - selectionstart;
string part2 = myString.Substring(selectionstart, length);
sb.Append(part1);
sb.Append("a");
sb.Append(part2);
textBox1.Text = sb.ToString();
break;
}
else
{
string myString = textBox1.Text.ToString();
myString = myString.Substring(0, myString.Length - 1);
textBox1.Text = myString;
textBox1.AppendText("a");
break;
}
}
break;
}
case 0:
{
if (clicked > 1)
{
if (selectionstart < textBox1.Text.Length)
{
string myString = textBox1.Text.ToString();
StringBuilder sb = new StringBuilder();
string part1 = myString.Substring(0, selectionstart);
int length = myString.Length - selectionstart - 1;
string part2 = myString.Substring(selectionstart + 1, length);
sb.Append(part1);
sb.Append("b");
sb.Append(part2);
textBox1.Text = sb.ToString();
break;
}
else
{
string myString = textBox1.Text.ToString();
myString = myString.Substring(0, myString.Length - 1);
textBox1.Text = myString;
textBox1.AppendText("b");
break;
}
}
else
{
if (selectionstart < textBox1.Text.Length)
{
string myString = textBox1.Text.ToString();
StringBuilder sb = new StringBuilder();
string part1 = myString.Substring(0, selectionstart);
int length = myString.Length - selectionstart;
string part2 = myString.Substring(selectionstart, length);
sb.Append(part1);
sb.Append("b");
sb.Append(part2);
textBox1.Text = sb.ToString();
break;
}
else
{
string myString = textBox1.Text.ToString();
myString = myString. Substring(0, myString.Length - 1);
textBox1.Text = myString;
textBox1.AppendText("b");
break;
}
}
break;
}
}
}