[英]Add text (push) to textbox or richtextbox?
I'm trying to create a chat application like msn. 我正在尝试创建一个像msn这样的聊天应用程序。 When i do "textBox.Text = textBox.Text+text" it updates the textbox and the text i got selected is no longer selected.
当我执行“ textBox.Text = textBox.Text + text”时,它将更新文本框,并且不再选择我选择的文本。 In MSN you can have selected text and still recieve messages in different colors etc.. How do they do it?
在MSN中,您可以选择文本并仍以不同的颜色等接收消息。它们是如何做到的? I figure its something like push messages, maybe they create a new textbox under another textbox?
我认为它类似于推送消息,也许他们在另一个文本框下创建了一个新的文本框? Any clues?
有什么线索吗?
I hope you guys know what i'm talking about here. 我希望你们知道我在说什么。 I just want my text to behave like MSN used to do, not update the whole textbox, just push a new message under the current message etc.
我只希望我的文本表现得像以前的MSN一样,不更新整个文本框,而只是在当前消息下推送新消息,等等。
If I understand your question, you just want text to stay selected when you append messages to a RichTextBox? 如果我理解您的问题,您只是希望在将消息附加到RichTextBox时保持选中状态?
int selectionStart = textBox.SelectionStart;
int selectionLength = textBox.SelectionLength;
int carat = textBox.TextLength;
textBox.Text += Environment.NewLine;
textBox.Text += newText;
//optional styling code for newly appended text
textBox.Select(carat, newText.Length);
textBox.SelectionColor = //value;
//etc.
//reapply original selection
if(selectionStart >= 0 && selectionLength > 0)
{
textBox.Select(selectionStart, selectionLength);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.