-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRichTextBox.cs
More file actions
41 lines (34 loc) · 1.21 KB
/
RichTextBox.cs
File metadata and controls
41 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Windows.Forms;
public static class RichTextBoxExtensions {
public static void AppendText(this System.Windows.Forms.RichTextBox box, string text, System.Drawing.Color color) {
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = color;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
}
}
namespace Examples {
class MainForm : Form {
public static void Main() {
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
public MainForm() {
Text = "RichTextBox example";
richTextBox.Parent = this;
richTextBox.Dock = DockStyle.Fill;
richTextBox.AppendText("Colored text :\n");
richTextBox.SelectionStart = richTextBox.TextLength;
richTextBox.SelectionColor = System.Drawing.Color.Red;
richTextBox.AppendText(" Red\n");
richTextBox.SelectionColor = System.Drawing.Color.Green;
richTextBox.AppendText(" Green\n");
richTextBox.SelectionColor = System.Drawing.Color.Blue;
richTextBox.AppendText(" Blue\n");
richTextBox.SelectionColor = richTextBox.ForeColor;
}
private RichTextBox richTextBox = new RichTextBox();
}
}