summaryrefslogtreecommitdiff
path: root/script-editor/CustomControl.cs
blob: 829565c1ebac5ce15af9b6f3f0587e6b90c2ae37 (plain)
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
using System.Windows.Forms;

namespace CustomControl
{
    public class MyPanel : Panel
    {
        protected override void OnPaintBackground(PaintEventArgs pevent) { }
    }

    public class MyRichTextBox : RichTextBox
    {
        private bool allowedKeypress;
        
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            e.Handled = true;
            if (!allowedKeypress)
                System.Media.SystemSounds.Beep.Play();
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            allowedKeypress = e.Control && (e.KeyCode == Keys.A || e.KeyCode == Keys.C || e.KeyCode == Keys.Insert || e.KeyCode == Keys.Y || e.KeyCode == Keys.Z);

            if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete || (e.Control && (e.KeyCode == Keys.V || e.KeyCode == Keys.X)) || (e.Shift && (e.KeyCode == Keys.Insert || e.KeyCode == Keys.Delete)))
            {
                if (e.KeyCode == Keys.Delete || (e.Shift && (e.KeyCode == Keys.Insert || e.KeyCode == Keys.Delete)))
                    System.Media.SystemSounds.Beep.Play();
                e.Handled = true;
            }
            else
                base.OnKeyDown(e);
        }
    }
}