Skip to content

Commit aac4783

Browse files
committed
Added QlibNumericBox
1 parent 7148e95 commit aac4783

16 files changed

+300
-303
lines changed

.vs/QuickLibrary/v16/.suo

23 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

QuickLibrary/QlibListView.cs

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System.Windows.Forms;
2+
using System.Drawing;
3+
using System.Drawing.Text;
4+
using System.ComponentModel;
5+
using System;
6+
7+
namespace QuickLibrary
8+
{
9+
public class QlibListView : ListView
10+
{
11+
// LOCKED VARIABLES
12+
13+
[Browsable(false), Obsolete("Don't use this! (OnwerDraw = True)", true), EditorBrowsable(EditorBrowsableState.Never)]
14+
public new enum OwnerDraw { };
15+
16+
17+
private Color headerColor = ThemeManager.LightSecondColor;
18+
19+
public QlibListView()
20+
{
21+
base.OwnerDraw = true;
22+
}
23+
24+
public void SetDarkMode(bool dark)
25+
{
26+
if (dark)
27+
{
28+
this.BackColor = ThemeManager.DarkBackColor;
29+
this.headerColor = ThemeManager.DarkSecondColor;
30+
this.ForeColor = Color.White;
31+
}
32+
else
33+
{
34+
this.BackColor = ThemeManager.LightBackColor;
35+
this.headerColor = ThemeManager.LightSecondColor;
36+
this.ForeColor = Color.Black;
37+
}
38+
}
39+
40+
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
41+
{
42+
base.OnDrawColumnHeader(e);
43+
44+
using (SolidBrush backBrush = new SolidBrush(headerColor))
45+
{
46+
e.Graphics.FillRectangle(backBrush, e.Bounds);
47+
}
48+
49+
if (e.Header.Index != this.Columns.Count - 1)
50+
{
51+
using (Pen borderPen = new Pen(this.BackColor))
52+
{
53+
e.Graphics.DrawLine(borderPen, e.Bounds.X + e.Bounds.Width - 1, e.Bounds.Y, e.Bounds.X + e.Bounds.Width - 1, e.Bounds.Height);
54+
}
55+
}
56+
57+
using (SolidBrush foreBrush = new SolidBrush(this.ForeColor))
58+
{
59+
Rectangle newBounds = e.Bounds;
60+
newBounds.X += 6;
61+
newBounds.Y += 3;
62+
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
63+
e.Graphics.DrawString(e.Header.Text, e.Font, foreBrush, newBounds);
64+
}
65+
}
66+
67+
protected override void OnDrawItem(DrawListViewItemEventArgs e)
68+
{
69+
base.OnDrawItem(e);
70+
e.DrawDefault = true;
71+
}
72+
}
73+
}

QuickLibrary/QlibNumericBox.cs

+169-39
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,199 @@
1-
using System.Drawing;
1+
using System;
2+
using System.ComponentModel;
3+
using System.Drawing;
24
using System.Windows.Forms;
35

46
namespace QuickLibrary
57
{
6-
public class QlibNumericBox : NumericUpDown
8+
public class QlibNumericBox : Panel
79
{
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+
877
public QlibNumericBox()
978
{
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;
1294
}
1395

14-
public void SetDarkMode(bool dark)
96+
// PRIVATE BODY
97+
98+
private void Numeric_ValueChanged(object sender, EventArgs e)
1599
{
16-
if (dark)
17-
{
18-
this.BackColor = ThemeManager.DarkSecondColor;
19-
this.ForeColor = Color.White;
20-
}
100+
OnValueChanged(e);
21101
}
22102

23-
protected override void OnPaint(PaintEventArgs e)
103+
private void QlibNumericBox_Click(object sender, EventArgs e)
24104
{
25-
e.Graphics.Clear(this.BackColor);
105+
numeric.Select();
106+
}
26107

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()
29121
{
30-
arrowsBrush = new SolidBrush(ThemeManager.BorderColor);
122+
SetStyle(ControlStyles.UserPaint, true);
123+
Controls[0].Visible = false;
31124
}
32125

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)
40127
{
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);
46129

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)
50151
{
51-
this.Focus();
52-
if (e.Y > this.Height / 2)
152+
if (e.X > Width - 18)
53153
{
54-
if (this.Value > this.Minimum)
154+
Focus();
155+
if (e.Y > Height / 2)
55156
{
56-
this.Value--;
157+
if (Value > Minimum)
158+
{
159+
Value--;
160+
}
57161
}
58-
}
59-
else
60-
{
61-
if (this.Value < this.Maximum)
162+
else
62163
{
63-
this.Value++;
164+
if (Value < Maximum)
165+
{
166+
Value++;
167+
}
64168
}
65169
}
66170
}
67171
}
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;
68198
}
69199
}

0 commit comments

Comments
 (0)