Windows Forms: Multiple Color In RichTextBox in C#
By FoxLearn 5/24/2017 9:08:09 PM 4.59K
How to Use Multiple Color in RichTextBox using C#
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "MultipleColorRichText" and then click OK
Step 3: Design your form as below
Add a ColorDialog to your form as below
Step 3: Add code to handle your form
using System; using System.Drawing; using System.Windows.Forms; namespace MultipleColorRichText { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Color _color = Color.Blue; bool _first = true; private void btnSend_Click(object sender, EventArgs e) { //Set color to RichTextBox rtfResult.SelectionColor = _color; if (_first) rtfResult.SelectedText = txtValue.Text; else rtfResult.SelectedText = Environment.NewLine + txtValue.Text; _first = false; txtValue.Clear(); txtValue.Focus(); } private void pColor_Click(object sender, EventArgs e) { //Open color dialog if (colorDialog1.ShowDialog() == DialogResult.OK) { _color = colorDialog1.Color; pColor.BackColor = _color; } } } }
VIDEO TUTORIALS
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024
What Are RESTful Web Services?
02/19/2024