如何控制光标?

dvdvip 2008-07-04 07:40:58
例如, 点击Button1后, 输入框显示"She is a pretty girl.". 按钮的代码如下:

TextBox1.Text=@"She is a pretty girl.";


但是, 我还想点击按钮后, 让光标出现在pretty的前面.


请问如何实现?


谢谢了.
...全文
112 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jcrjia 2008-07-04
  • 打赏
  • 举报
回复
up
学习了
我姓区不姓区 2008-07-04
  • 打赏
  • 举报
回复

textBox1.Focus();
textBox1.SelectionStart = textBox1.Text.IndexOf("pretty");
textBox1.SelectionLength = 0;
zzyhuian06142 2008-07-04
  • 打赏
  • 举报
回复
Button _button = (Button)sender;
switch(_button.Text)
{
case "Show":
this.textBox1.Text="She is a pretty girl.";
this.button1.Text = "Mouse";
break;
case "Mouse":
this.textBox1.Focus();
this.textBox1.SelectionStart = this.textBox1.Text.IndexOf("pretty");
this.textBox1.SelectionLength=0;
this.button1.Text = "Show";
break;
}
wocow2316 2008-07-04
  • 打赏
  • 举报
回复
用TextBox1.SelectionStart 和TextBox1.SelectionLength

TextBox1.SelectionStart 是光标定位到哪里
TextBox1.SelectionLength 是选中字符的长度
51Crack 2008-07-04
  • 打赏
  • 举报
回复

TextBox1.SelectionStart = 9
TextBox1.SelectionLength = 0

110,825

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧