如何使上的RichTextBox串的特定部分粗体? [英] How to make a specific part of string Bold on richTextBox?
问题描述
我有一个基于表单和2 richTextBoxes在聊天应用程序!
I have a chat application that is based on a Form and 2 richTextBoxes !
richTextBox1
用于显示所有的谈话
richTextBox_TextToSend
用于输入要发送的消息
richTextBox1
is used to display all conversation
richTextBox_TextToSend
is used to type in the message to send
当用户键入消息,并按下回车键,将出现在richTextBox1输入文字
when a user types a message and hit the enter button, the entered text will appear in richTextBox1
private void button1_Click(object sender, EventArgs e)
{
// insert message to database
if(richTextBox_TextToSend.TextLength>0) {
string txt = richTextBox_TextToSend.Text;
// send the typed message
sendMessage(from,to,task_id,txt);
// show the typed text in the richTextBox1
richTextBox1.Text += from+": "+richTextBox_TextToSend.Text+"\n";
richTextBox_TextToSend.Clear();
}
}
变量从
string类型持有谁发送邮件(使用应用程序的用户)的名称
The variable from
of type string holds the name of who send the message (the user using the application)
如何只有在正常的字体样式加粗和其他文本显示的名称,以便在输入信息后,我看到
沙基卜优素菲:您好....
代替
沙基卜优素菲:你好...
How to display the name only in bold and other text in normal font style so after typing the message, I see
Chakib Yousfi : Hello....
instead of
Chakib Yousfi : Hello...
任何帮助将是非常美联社preciated。
Any help would be highly appreciated .
推荐答案
首先,你应该选择要大胆的文字:
First, you should select the text you want to make bold:
richTextBox1.SelectionStart = 0;
richTextBox1.SelectionLength = 13;
然后你就可以定义样式选定的文本:
And then you can define the style for the selected text:
richTextBox1.SelectionFont = new Font(richTextBox1.Font, FontStyle.Bold);
这篇关于如何使上的RichTextBox串的特定部分粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!