初级问题,如何实现,按下一button后,向TextBox的当前光标处输入一个字符串“hello”。

CYQ_96 2004-08-16 10:35:07
如题
...全文
169 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
boyxia 2004-08-16
  • 打赏
  • 举报
回复
#region 公式定义操作区按钮执行事件
private void AddString(RichTextBox RichTextBoxName,string AddString)
{
int CurPos = RichTextBoxName.SelectionStart;
RichTextBoxName.SelectedText=AddString;
RichTextBoxName.SelectionStart = CurPos+AddString.Length;
RichTextBoxName.Focus();
}

#endregion
rickjelly2004 2004-08-16
  • 打赏
  • 举报
回复
TextBox.text=TextBox.text & "hello";
alwaysinsist 2004-08-16
  • 打赏
  • 举报
回复
void Button_Click(Object O,EventArgs E)
{
if(!IsPostBack)
{
TextBox.Text="hello";
}
}


<asp:TextBox id="tb" runat=server />
<asp:Button id="bt" runat=server OnClick="Button_Click" />


看看行不!
mqmmx 2004-08-16
  • 打赏
  • 举报
回复
是不是这样
'从零位到光标位字符串
string s1=textBox1.Text.Substring(0,textBox1.SelectionStart);
'从光标位到字符串尾部的字符串
string s2=textBox1.Text.Substring(textBox1.SelectionStart,textBox1.Text.Length-textBox1.SelectionStart);

this.textBox1.Text=s1+"hello"+s2;
北京的雾霾天 2004-08-16
  • 打赏
  • 举报
回复
这样合不合的要求:
private void button3_Click(object sender, System.EventArgs e)
{
string sInsert="Hello";
int p=this.textBox1.SelectionStart;

this.textBox1.Text=this.textBox1.Text.Substring(0,p)+sInsert+this.textBox1.Text.Substring(p);
this.textBox1.SelectionStart=p+sInsert.Length;
this.textBox1.Focus();
}
试试看!
猿猿粪 2004-08-16
  • 打赏
  • 举报
回复
在.net中 如果你找到答案 tell me ok?
猿猿粪 2004-08-16
  • 打赏
  • 举报
回复
在VB6中 可以在点击事件中 用SendKey "你要输入的内容" 就会在光标出输出
CYQ_96 2004-08-16
  • 打赏
  • 举报
回复
我要求的是在TextBox中已经有内容的情况下,插入一个字符串进去。例如,在TextBox中已有内容"Tom said and left",如果光标在said之后时,按下button后,TextBox的内容变成"Tom said hello and left"。(要求简单地向光标处插入字符,如光标在Tom后,则TextBox变成"Tom hello said and left",不用判断生成串的意义)
CYQ_96 2004-08-16
  • 打赏
  • 举报
回复
TextBox中已经有内容了,我要求的是,向TextBox中插入内容。比如,在TextBox中已有内容"Tom said and left"了,光前光标在said之后,要求按下button后,TextBox的内容变成"Tome said hello and left"。(这只是个例子,实际要求是光标可在TextBox中的任何位置)
Beetle2008 2004-08-16
  • 打赏
  • 举报
回复
在button中加下以下代码:
TextBox.text="hello";

110,568

社区成员

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

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

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