TextBox.Text = "abcdefg"
问题:
区别 <光标正在字母b后面的位置> 和 <光标正在字母f后面的位置> ,
用代码该怎么表达?
谢谢!
5 个解决方案
#1
this.textBox1.SelectionStart;
#2
if (ctls.GetType().Name == txt)
{
TextBox tb = new TextBox();
try
{
tb = (TextBox)fr.Controls.Find(ctls.Name, true)[0];
if (lstControl.IndexOf(tb) < 0)
{
lstControl.Add(tb);
if (tb.Text.Trim().IndexOf(textBox1.Text.Trim()) >= 0)
{
tb.Focus();
int start = tb.Text.IndexOf(textBox1.Text.Trim());
int end = textBox1.Text.Trim().Length;
tb.Select(start, end);
return 1;
}
}
else
{
return 0;
}
}
catch (Exception ex)
{ }
}
里面找!
{
TextBox tb = new TextBox();
try
{
tb = (TextBox)fr.Controls.Find(ctls.Name, true)[0];
if (lstControl.IndexOf(tb) < 0)
{
lstControl.Add(tb);
if (tb.Text.Trim().IndexOf(textBox1.Text.Trim()) >= 0)
{
tb.Focus();
int start = tb.Text.IndexOf(textBox1.Text.Trim());
int end = textBox1.Text.Trim().Length;
tb.Select(start, end);
return 1;
}
}
else
{
return 0;
}
}
catch (Exception ex)
{ }
}
里面找!
#3
#4
LZ试试这个:
this.textBox1.Focus();
string text = textBox1.Text;
int cursorIndex = this.textBox1.SelectionStart;
StringBuilder sbInfo = new StringBuilder("Cursor is ");
if (cursorIndex <= 0)
{
sbInfo.Append("at the beginning of the sentence, ");
}
else
{
char charBeforeCursor = text[cursorIndex - 1];
sbInfo.Append(string.Format("behind letter '{0}', ", charBeforeCursor));
}
if (cursorIndex >= text.Length)
{
sbInfo.Append("and at the ending of the sentence.");
}
else
{
char charAfterCursor = text[cursorIndex];
sbInfo.Append(string.Format("and before letter '{0}'", charAfterCursor));
}
MessageBox.Show(sbInfo.ToString());
#5
TextBox.SelectionStart // 光标所在位置索引
#1
this.textBox1.SelectionStart;
#2
if (ctls.GetType().Name == txt)
{
TextBox tb = new TextBox();
try
{
tb = (TextBox)fr.Controls.Find(ctls.Name, true)[0];
if (lstControl.IndexOf(tb) < 0)
{
lstControl.Add(tb);
if (tb.Text.Trim().IndexOf(textBox1.Text.Trim()) >= 0)
{
tb.Focus();
int start = tb.Text.IndexOf(textBox1.Text.Trim());
int end = textBox1.Text.Trim().Length;
tb.Select(start, end);
return 1;
}
}
else
{
return 0;
}
}
catch (Exception ex)
{ }
}
里面找!
{
TextBox tb = new TextBox();
try
{
tb = (TextBox)fr.Controls.Find(ctls.Name, true)[0];
if (lstControl.IndexOf(tb) < 0)
{
lstControl.Add(tb);
if (tb.Text.Trim().IndexOf(textBox1.Text.Trim()) >= 0)
{
tb.Focus();
int start = tb.Text.IndexOf(textBox1.Text.Trim());
int end = textBox1.Text.Trim().Length;
tb.Select(start, end);
return 1;
}
}
else
{
return 0;
}
}
catch (Exception ex)
{ }
}
里面找!
#3
#4
LZ试试这个:
this.textBox1.Focus();
string text = textBox1.Text;
int cursorIndex = this.textBox1.SelectionStart;
StringBuilder sbInfo = new StringBuilder("Cursor is ");
if (cursorIndex <= 0)
{
sbInfo.Append("at the beginning of the sentence, ");
}
else
{
char charBeforeCursor = text[cursorIndex - 1];
sbInfo.Append(string.Format("behind letter '{0}', ", charBeforeCursor));
}
if (cursorIndex >= text.Length)
{
sbInfo.Append("and at the ending of the sentence.");
}
else
{
char charAfterCursor = text[cursorIndex];
sbInfo.Append(string.Format("and before letter '{0}'", charAfterCursor));
}
MessageBox.Show(sbInfo.ToString());
#5
TextBox.SelectionStart // 光标所在位置索引