Windows Forms: Multiple Color In RichTextBox in C#
By FoxLearn 5/24/2017 9:08:09 PM 4.83K
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
Flat Able Admin Dashboard Template
11/18/2024
Regal Admin Dashboard Template
11/18/2024
Plus Admin Dashboard Template
11/18/2024
Admin Tailwind CSS Admin Dashboard Template
11/18/2024