问题描述
这段代码有什么问题?试图让我的文本插入文本框的开头而不是底部.
私有无效execute_Click(对象发送者,EventArgs e){startFinshBox.Text = "开始时间:" + printTime()+"";startFinshBox.Text.Insert(0,printTime()+": 检索结果...\n");}但它不会将第二行插入到 rtb 中.我也尝试过 startFinishBox.SelectionStart = 0 ,但没有任何区别.我还缺什么吗?
谢谢,心理医生
startFinshBox.Text
是一个字符串,它是 C# 中的不可变类型.string.Insert()
将返回修改后的字符串作为结果,但您的代码将丢弃它.要使其工作,您必须将代码更改为:
private void execute_Click(object sender, EventArgs e){startFinshBox.Text = "开始时间:" + printTime()+"";startFinshBox.Text = startFinshBox.Text.Insert(0,printTime()+": 检索结果...\n");}
Whats wrong with this code? Trying to get my text to insert at the beginning of the textbox rather than at the bottom.
private void execute_Click(object sender, EventArgs e){ startFinshBox.Text = "Start Time: " + printTime()+""; startFinshBox.Text.Insert(0,printTime()+": Retrieving Results...\n"); }
But it will not insert the second line into the rtb. I have tried with startFinishBox.SelectionStart = 0 as well, and it made no difference. Am I missing something else?
Thanks, Psy
startFinshBox.Text
is a string, which is an immutable type in C#. string.Insert()
will return the modified string as a result, but it your code you discard it. To make it work, you have to change the code to:
private void execute_Click(object sender, EventArgs e){
startFinshBox.Text = "Start Time: " + printTime()+"";
startFinshBox.Text = startFinshBox.Text.Insert(0,printTime()+": Retrieving Results...\n");
}
这篇关于在富文本框顶部插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!