- Back to Home »
- Windows Applications »
- RichTextBox
Posted by :
Sudhir Chekuri
Monday, 15 February 2016
It is used to take input from user like textbox and it is capable of holding text styles.
Default Event: TextChanged which is fired when text in RichTextBox changed in runtime.
Example code to print text in RichTextBox in label with a change in text
Default Event: TextChanged which is fired when text in RichTextBox changed in runtime.
Example code to print text in RichTextBox in label with a change in text
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
label1.Text = richTextBox1.Text;
}
Example code to print colourful text with styles in RichTextBox
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.Font = new Font("Consolas", 18f, FontStyle.Bold);
richTextBox1.BackColor = Color.AliceBlue;
string[] words =
{
"Hello", "World"
};
Color[] colors =
{
Color.Aqua,
Color.CadetBlue
};
for (int i = 0; i <
words.Length; i++)
{
string word = words[i];
Color color = colors[i];
{
richTextBox1.SelectionBackColor = color;
richTextBox1.AppendText(word);
richTextBox1.SelectionBackColor = Color.AliceBlue;
richTextBox1.AppendText(" ");
}
}
}