Добавление текста в RichTextBox с различными атрибутами - Visual Basic .NET

Узнай цену своей работы

Формулировка задачи:

Всем здравствуйте.Как из кода занести в одно и тоже RichTextBox одну строчку со шрифтом синего цвета,а следующую со шрифтом красного цвета, все последующие должны заноситься со шрифтом чёрного цвета

Решение задачи: «Добавление текста в RichTextBox с различными атрибутами»

textual
Листинг программы
  1. Private Sub WriteTextToRichTextBox()
  2.         ' Clear all text from the RichTextBox;
  3.         richTextBox1.Clear()
  4.         ' Set the font for the opening text to a larger Arial font;
  5.         richTextBox1.SelectionFont = New Font("Arial", 16)
  6.         ' Assign the introduction text to the RichTextBox control.
  7.         RichTextBox1.SelectedText = "The following is a list of bulleted items:" + ControlChars.Cr
  8.         ' Set the Font for the first item to a smaller size Arial font.
  9.         richTextBox1.SelectionFont = New Font("Arial", 12)
  10.         ' Specify that the following items are to be added to a bulleted list.
  11.         richTextBox1.SelectionBullet = True
  12.         ' Set the color of the item text.
  13.         richTextBox1.SelectionColor = Color.Red
  14.         ' Assign the text to the bulleted item.
  15.         richTextBox1.SelectedText = "Apples" + ControlChars.Cr
  16.         ' Apply same font since font settings do not carry to next line.
  17.         richTextBox1.SelectionFont = New Font("Arial", 12)
  18.         richTextBox1.SelectionColor = Color.Orange
  19.         richTextBox1.SelectedText = "Oranges" + ControlChars.Cr
  20.         richTextBox1.SelectionFont = New Font("Arial", 12)
  21.         richTextBox1.SelectionColor = Color.Purple
  22.         richTextBox1.SelectedText = "Grapes" + ControlChars.Cr
  23.         ' End the bulleted list.
  24.         richTextBox1.SelectionBullet = False
  25.         ' Specify the font size and string for text displayed below bulleted list.
  26.         richTextBox1.SelectionFont = New Font("Arial", 16)
  27.         richTextBox1.SelectedText = "Bulleted Text Complete!"
  28.     End Sub

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

10   голосов , оценка 3.8 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы