This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
MainFormRichTextBox.cs
70 lines (62 loc) · 2.33 KB
/
MainFormRichTextBox.cs
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
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace CustomUIEditor
{
public partial class MainForm : Form
{
private void richTextBoxMethod_Click(object sender, EventArgs e)
{
string methodName = sender.GetType().GetProperty("Tag").GetValue(sender, null) as string;
if (methodName == null || methodName == string.Empty)
{
return;
}
try
{
this.richTextBox.GetType().InvokeMember(
methodName,
System.Reflection.BindingFlags.InvokeMethod,
null /*binder*/,
this.richTextBox,
null /*args*/);
}
catch { }
}
private void richTextBox_TextChanged(object sender, EventArgs e)
{
this.validateToolStripButton.Enabled = (this.richTextBox.TextLength > 0);
this.colorTimer.Stop();
this.colorTimer.Start();
}
private void richTextBox_ModifiedChanged(object sender, EventArgs e)
{
if (this.package != null)
{
this.package.IsDirty = this.richTextBox.Modified;
this.saveToolStripButton.Enabled = this.richTextBox.Modified;
this.saveToolStripMenuItem.Enabled = this.richTextBox.Modified;
}
}
private void richTextBox_SelectionChanged(object sender, EventArgs e)
{
int start = this.richTextBox.SelectionStart;
int length = this.richTextBox.SelectionLength;
int line = this.richTextBox.GetLineFromCharIndex(start + length);
int col = start + length - this.richTextBox.GetFirstCharIndexFromLine(line);
this.line.Text = "Ln " + (line + 1);
this.column.Text = "Col " + (col + 1);
this.UpdateSelectionControlEnableState(length > 0);
}
private void UpdateSelectionControlEnableState(bool enable)
{
this.cutContextMenuItem.Enabled = enable;
this.deleteContextMenuItem.Enabled = enable;
this.copyContextMenuItem.Enabled = enable;
}
private void deleteContextMenuItem_Click(object sender, EventArgs e)
{
this.richTextBox.SelectedText = "";
}
}
}