|
1 |
| -using System.Drawing; |
| 1 | +using System; |
| 2 | +using System.ComponentModel; |
| 3 | +using System.Drawing; |
2 | 4 | using System.Windows.Forms;
|
3 | 5 |
|
4 | 6 | namespace QuickLibrary
|
5 | 7 | {
|
6 |
| - public class QlibNumericBox : NumericUpDown |
| 8 | + public class QlibNumericBox : Panel |
7 | 9 | {
|
| 10 | + // PRIVATE FIELDS |
| 11 | + |
| 12 | + private InternalNumericUpDown numeric; |
| 13 | + |
| 14 | + // HIDDEN PROPS |
| 15 | + |
| 16 | + [Browsable(false)] |
| 17 | + public new Image BackgroundImage => base.BackgroundImage; |
| 18 | + |
| 19 | + [Browsable(false)] |
| 20 | + public new ImageLayout BackgroundImageLayout => base.BackgroundImageLayout; |
| 21 | + |
| 22 | + [Browsable(false)] |
| 23 | + public new Color ForeColor => base.ForeColor; |
| 24 | + |
| 25 | + [Browsable(false)] |
| 26 | + public new Color BackColor => base.BackColor; |
| 27 | + |
| 28 | + [Browsable(false)] |
| 29 | + public new Cursor Cursor => base.Cursor; |
| 30 | + |
| 31 | + [Browsable(false)] |
| 32 | + public new BorderStyle BorderStyle => base.BorderStyle; |
| 33 | + |
| 34 | + [Browsable(false)] |
| 35 | + public new Font Font => base.Font; |
| 36 | + |
| 37 | + [Browsable(false)] |
| 38 | + public new bool AutoScroll => base.AutoScroll; |
| 39 | + |
| 40 | + [Browsable(false)] |
| 41 | + public new bool AutoSize => base.AutoSize; |
| 42 | + |
| 43 | + [Browsable(false)] |
| 44 | + public new AutoSizeMode AutoSizeMode => base.AutoSizeMode; |
| 45 | + |
| 46 | + [Browsable(false)] |
| 47 | + public new Padding Padding => base.Padding; |
| 48 | + |
| 49 | + [Browsable(false)] |
| 50 | + public new RightToLeft RightToLeft => base.RightToLeft; |
| 51 | + |
| 52 | + // PUBLIC PROPS |
| 53 | + |
| 54 | + [Category("Qlib props"), Browsable(true), Description("Value")] |
| 55 | + public decimal Value |
| 56 | + { |
| 57 | + get { return numeric.Value; } |
| 58 | + set { numeric.Value = value; } |
| 59 | + } |
| 60 | + |
| 61 | + [Category("Qlib props"), Browsable(true), Description("Maximum")] |
| 62 | + public decimal Maximum |
| 63 | + { |
| 64 | + get { return numeric.Maximum; } |
| 65 | + set { numeric.Maximum = value; } |
| 66 | + } |
| 67 | + |
| 68 | + [Category("Qlib props"), Browsable(true), Description("Minimum")] |
| 69 | + public decimal Minimum |
| 70 | + { |
| 71 | + get { return numeric.Minimum; } |
| 72 | + set { numeric.Minimum = value; } |
| 73 | + } |
| 74 | + |
| 75 | + // CONSTRUCTOR |
| 76 | + |
8 | 77 | public QlibNumericBox()
|
9 | 78 | {
|
10 |
| - SetStyle(ControlStyles.UserPaint, true); |
11 |
| - this.Controls[0].Visible = false; |
| 79 | + numeric = new InternalNumericUpDown(); |
| 80 | + |
| 81 | + numeric.Location = new Point(7, 7); |
| 82 | + numeric.BorderStyle = BorderStyle.None; |
| 83 | + numeric.BackColor = BackColor; |
| 84 | + |
| 85 | + Controls.Add(numeric); |
| 86 | + |
| 87 | + base.Cursor = Cursors.IBeam; |
| 88 | + |
| 89 | + SizeChanged += QlibNumericBox_SizeChanged; |
| 90 | + GotFocus += QlibNumericBox_GotFocus; |
| 91 | + Click += QlibNumericBox_Click; |
| 92 | + |
| 93 | + numeric.ValueChanged += Numeric_ValueChanged; |
12 | 94 | }
|
13 | 95 |
|
14 |
| - public void SetDarkMode(bool dark) |
| 96 | + // PRIVATE BODY |
| 97 | + |
| 98 | + private void Numeric_ValueChanged(object sender, EventArgs e) |
15 | 99 | {
|
16 |
| - if (dark) |
17 |
| - { |
18 |
| - this.BackColor = ThemeManager.DarkSecondColor; |
19 |
| - this.ForeColor = Color.White; |
20 |
| - } |
| 100 | + OnValueChanged(e); |
21 | 101 | }
|
22 | 102 |
|
23 |
| - protected override void OnPaint(PaintEventArgs e) |
| 103 | + private void QlibNumericBox_Click(object sender, EventArgs e) |
24 | 104 | {
|
25 |
| - e.Graphics.Clear(this.BackColor); |
| 105 | + numeric.Select(); |
| 106 | + } |
26 | 107 |
|
27 |
| - Brush arrowsBrush = new SolidBrush(this.ForeColor); |
28 |
| - if (!this.Enabled) |
| 108 | + private void QlibNumericBox_GotFocus(object sender, EventArgs e) |
| 109 | + { |
| 110 | + numeric.Focus(); |
| 111 | + } |
| 112 | + |
| 113 | + private void QlibNumericBox_SizeChanged(object sender, EventArgs e) |
| 114 | + { |
| 115 | + numeric.Size = new Size(Size.Width - 14, numeric.Size.Height); |
| 116 | + } |
| 117 | + |
| 118 | + internal class InternalNumericUpDown : NumericUpDown |
| 119 | + { |
| 120 | + public InternalNumericUpDown() |
29 | 121 | {
|
30 |
| - arrowsBrush = new SolidBrush(ThemeManager.BorderColor); |
| 122 | + SetStyle(ControlStyles.UserPaint, true); |
| 123 | + Controls[0].Visible = false; |
31 | 124 | }
|
32 | 125 |
|
33 |
| - e.Graphics.FillPolygon(arrowsBrush, new PointF[] |
34 |
| - { |
35 |
| - new PointF(this.Width - 14, 15), |
36 |
| - new PointF(this.Width - 10, 19), |
37 |
| - new PointF(this.Width - 6, 15) |
38 |
| - }); |
39 |
| - e.Graphics.FillPolygon(arrowsBrush, new PointF[] |
| 126 | + protected override void OnPaint(PaintEventArgs e) |
40 | 127 | {
|
41 |
| - new PointF(this.Width - 15, 10), |
42 |
| - new PointF(this.Width - 10, 5), |
43 |
| - new PointF(this.Width - 6, 10) |
44 |
| - }); |
45 |
| - } |
| 128 | + e.Graphics.Clear(BackColor); |
46 | 129 |
|
47 |
| - protected override void OnMouseClick(MouseEventArgs e) |
48 |
| - { |
49 |
| - if (e.X > this.Width - 18) |
| 130 | + Brush arrowsBrush = new SolidBrush(ForeColor); |
| 131 | + if (!Enabled) |
| 132 | + { |
| 133 | + arrowsBrush = new SolidBrush(ThemeManager.BorderColor); |
| 134 | + } |
| 135 | + |
| 136 | + e.Graphics.FillPolygon(arrowsBrush, new PointF[] |
| 137 | + { |
| 138 | + new PointF(Width - 14, 15), |
| 139 | + new PointF(Width - 10, 19), |
| 140 | + new PointF(Width - 6, 15) |
| 141 | + }); |
| 142 | + e.Graphics.FillPolygon(arrowsBrush, new PointF[] |
| 143 | + { |
| 144 | + new PointF(Width - 15, 10), |
| 145 | + new PointF(Width - 10, 5), |
| 146 | + new PointF(Width - 6, 10) |
| 147 | + }); |
| 148 | + } |
| 149 | + |
| 150 | + protected override void OnMouseClick(MouseEventArgs e) |
50 | 151 | {
|
51 |
| - this.Focus(); |
52 |
| - if (e.Y > this.Height / 2) |
| 152 | + if (e.X > Width - 18) |
53 | 153 | {
|
54 |
| - if (this.Value > this.Minimum) |
| 154 | + Focus(); |
| 155 | + if (e.Y > Height / 2) |
55 | 156 | {
|
56 |
| - this.Value--; |
| 157 | + if (Value > Minimum) |
| 158 | + { |
| 159 | + Value--; |
| 160 | + } |
57 | 161 | }
|
58 |
| - } |
59 |
| - else |
60 |
| - { |
61 |
| - if (this.Value < this.Maximum) |
| 162 | + else |
62 | 163 | {
|
63 |
| - this.Value++; |
| 164 | + if (Value < Maximum) |
| 165 | + { |
| 166 | + Value++; |
| 167 | + } |
64 | 168 | }
|
65 | 169 | }
|
66 | 170 | }
|
67 | 171 | }
|
| 172 | + |
| 173 | + // PUBLIC METHODS |
| 174 | + |
| 175 | + public void SetDarkMode(bool dark) |
| 176 | + { |
| 177 | + if (dark) |
| 178 | + { |
| 179 | + base.BackColor = ThemeManager.DarkSecondColor; |
| 180 | + numeric.ForeColor = Color.White; |
| 181 | + } |
| 182 | + else |
| 183 | + { |
| 184 | + base.BackColor = ThemeManager.LightSecondColor; |
| 185 | + numeric.ForeColor = Color.Black; |
| 186 | + } |
| 187 | + numeric.BackColor = ThemeManager.DarkSecondColor; |
| 188 | + } |
| 189 | + |
| 190 | + // EVENTS |
| 191 | + |
| 192 | + protected virtual void OnValueChanged(EventArgs e) |
| 193 | + { |
| 194 | + ValueChanged?.Invoke(this, e); |
| 195 | + } |
| 196 | + |
| 197 | + public event EventHandler ValueChanged; |
68 | 198 | }
|
69 | 199 | }
|
0 commit comments