RichTextBox полужирный текст - PullRequest
0 голосов
/ 13 мая 2019

Я заполняю richtextbox информацией, полученной из текстовых полей. Мне нужно, чтобы ввод от пользователя получил жирный шрифт в Richtextbox. Я пробовал разные ответы в SO, но либо я делаю что-то не так, либо не могу найти правильный ответ на этот вопрос.

Я пробовал RTF и приложение:

rtbGeneratedText.Text += @"In answer to your request regarding " + 
    rtbSpecialRequest.Text +
    " for your booking " +
    bookingNumberTxt.Text +
    " the hotel has informed us that unfortunately it is not possible." + "\r\n" + 
    "Please let us know if this negative answer will affect your reservation in any way.";

1 Ответ

0 голосов
/ 13 мая 2019

Вот как вы можете Полужирный несколько слов:

string target = "the hotel has informed us that unfortunately it is not possible";
RichTextBox1.SelectionStart = RichTextBox1.Text.IndexOf(target);
RichTextBox1.SelectionLength = target.Length;
RichTextBox1.SelectionFont = new Font(RichTextBox1.Font, FontStyle.Bold);

Или, если хотите Полужирный весь текст:

RichTextBox1.SelectionStart = 0;
RichTextBox1.SelectionLength = RichTextBox1.Length;
RichTextBox1.SelectionFont = new Font(RichTextBox1.Font, FontStyle.Bold);
...