forked from amoamare/PS5CodeReader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadOnlyRichTextBox.cs
More file actions
91 lines (78 loc) · 2.34 KB
/
ReadOnlyRichTextBox.cs
File metadata and controls
91 lines (78 loc) · 2.34 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using static Vanara.PInvoke.User32;
namespace PS5CodeReader
{
public class ReadOnlyRichTextBox : RichTextBox
{
internal static Color ColorError = Color.IndianRed;
internal static Color ColorSuccess = Color.MediumSeaGreen;
internal static Color ColorInformation = Color.DarkOrange;
internal static Color ColorDetail = Color.MediumBlue;
public ReadOnlyRichTextBox()
{
ReadOnly = true;
TabStop = false;
_ = HideCaret(Handle);
}
public override Color BackColor => Color.White;
internal void AppendText(string text, Color color)
{
if (InvokeRequired)
{
_ = Invoke(new MethodInvoker(() => AppendText(text, color)));
return;
}
SelectionStart = TextLength;
SelectionLength = 0;
SelectionColor = color;
base.AppendText(text);
SelectionColor = ForeColor;
Select(Text.Length, 0);
SelectionStart = Text.Length;
SelectionLength = 0;
ScrollToCaret();
}
internal new void AppendText(string text)
{
AppendText(text, ForeColor);
}
internal void AppendLine(string text)
{
if (InvokeRequired)
{
_ = Invoke(new MethodInvoker(() => AppendLine(text)));
return;
}
AppendText($"{text}{Environment.NewLine}");
}
internal void Okay()
{
AppendLine("OK", ColorSuccess);
}
internal void Fail()
{
AppendLine("Fail", ColorError);
}
internal void Fail(string reason)
{
AppendLine("Fail", ColorError);
AppendLine(reason, ColorError);
}
internal void AppendLine(string text, Color color)
{
AppendText($"{text}{Environment.NewLine}", color);
}
internal void Append(string text)
{
if (InvokeRequired)
{
_ = Invoke(new MethodInvoker(() => Append(text)));
return;
}
AppendText(text);
}
internal void Append(string text, Color color)
{
AppendText(text, color);
}
}
}