Skip to content

Commit 7824676

Browse files
committed
A lot of major changes
1 parent 1e8a1c2 commit 7824676

15 files changed

+424
-6
lines changed

.vs/QuickLibrary/v16/.suo

20 KB
Binary file not shown.
8 KB
Binary file not shown.

QuickLibrary/QlibCloseButton.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Drawing;
4+
using System.Windows.Forms;
5+
6+
namespace QuickLibrary
7+
{
8+
public class QlibCloseButton : Button
9+
{
10+
[Description("Light icon"), Category("Custom style")]
11+
public Image LightImage { get; set; }
12+
13+
[Description("Dark icon"), Category("Custom style")]
14+
public Image DarkImage { get; set; }
15+
16+
private bool darkMode = false;
17+
18+
public QlibCloseButton()
19+
{
20+
this.FlatAppearance.MouseDownBackColor = Color.FromArgb(241, 112, 122);
21+
this.FlatAppearance.MouseOverBackColor = Color.FromArgb(232, 17, 35);
22+
23+
this.MouseEnter += QlibCloseButton_MouseEnter;
24+
this.MouseLeave += QlibCloseButton_MouseLeave;
25+
}
26+
27+
private void QlibCloseButton_MouseLeave(object sender, EventArgs e)
28+
{
29+
if (darkMode)
30+
{
31+
this.Image = LightImage;
32+
}
33+
else
34+
{
35+
this.Image = DarkImage;
36+
}
37+
}
38+
39+
private void QlibCloseButton_MouseEnter(object sender, EventArgs e)
40+
{
41+
if (!darkMode)
42+
{
43+
this.Image = LightImage;
44+
}
45+
}
46+
47+
public void SetDarkMode(bool darkMode)
48+
{
49+
this.darkMode = darkMode;
50+
51+
QlibCloseButton_MouseLeave(this, EventArgs.Empty);
52+
}
53+
}
54+
}

QuickLibrary/QlibFixedForm.cs

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ namespace QuickLibrary
77
{
88
public class QlibFixedForm : Form
99
{
10-
public bool draggable = false;
11-
1210
[Browsable(false), Obsolete("Don't use this! (FormBorderStyle = None)", true), EditorBrowsable(EditorBrowsableState.Never)]
1311
public new enum FormBorderStyle { };
1412

@@ -41,17 +39,99 @@ public class QlibFixedForm : Form
4139
[Browsable(false), Obsolete("Don't use this! (Font = ThemeManager.DefaultFont)", true), EditorBrowsable(EditorBrowsableState.Never)]
4240
public new enum Font { };
4341

42+
private bool m_aeroEnabled;
43+
public bool draggable = false;
44+
45+
//private const int CS_DROPSHADOW = 0x00020000;
46+
//private const int WM_NCPAINT = 0x0085;
47+
48+
//[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
49+
//public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
50+
//[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
51+
//public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
52+
//[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
53+
54+
//public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
55+
//[System.Runtime.InteropServices.DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
56+
57+
//private static extern IntPtr CreateRoundRectRgn(
58+
// int nLeftRect,
59+
// int nTopRect,
60+
// int nRightRect,
61+
// int nBottomRect,
62+
// int nWidthEllipse,
63+
// int nHeightEllipse
64+
//);
65+
66+
//public struct MARGINS
67+
//{
68+
// public int leftWidth;
69+
// public int rightWidth;
70+
// public int topHeight;
71+
// public int bottomHeight;
72+
//}
73+
74+
//protected override CreateParams CreateParams
75+
//{
76+
// get
77+
// {
78+
// m_aeroEnabled = CheckAeroEnabled();
79+
// CreateParams cp = base.CreateParams;
80+
// if (!m_aeroEnabled)
81+
// cp.ClassStyle |= CS_DROPSHADOW;
82+
// return cp;
83+
// }
84+
//}
85+
86+
public const int WS_SYSMENU = 0x80000;
87+
public const int CS_DROPSHADOW = 0x20000;
88+
4489
protected override CreateParams CreateParams
4590
{
4691
get
4792
{
48-
const int CS_DROPSHADOW = 0x20000;
4993
CreateParams cp = base.CreateParams;
94+
//cp.Style = WS_SYSMENU;
5095
cp.ClassStyle |= CS_DROPSHADOW;
5196
return cp;
5297
}
5398
}
5499

100+
//private bool CheckAeroEnabled()
101+
//{
102+
// if (Environment.OSVersion.Version.Major >= 6)
103+
// {
104+
// int enabled = 0;
105+
// DwmIsCompositionEnabled(ref enabled);
106+
// return (enabled == 1) ? true : false;
107+
// }
108+
// return false;
109+
//}
110+
111+
//protected override void WndProc(ref Message m)
112+
//{
113+
// switch (m.Msg)
114+
// {
115+
// case WM_NCPAINT:
116+
// if (m_aeroEnabled)
117+
// {
118+
// var v = 2;
119+
// DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
120+
// MARGINS margins = new MARGINS()
121+
// {
122+
// bottomHeight = -1,
123+
// leftWidth = 0,
124+
// rightWidth = 0,
125+
// topHeight = 0
126+
// };
127+
// DwmExtendFrameIntoClientArea(this.Handle, ref margins);
128+
// }
129+
// break;
130+
// default: break;
131+
// }
132+
// base.WndProc(ref m);
133+
//}
134+
55135
public QlibFixedForm()
56136
{
57137
base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
@@ -65,6 +145,8 @@ public QlibFixedForm()
65145
base.BackgroundImage = null;
66146
base.BackgroundImageLayout = ImageLayout.Tile;
67147
base.Font = ThemeManager.DefaultFont;
148+
149+
m_aeroEnabled = !ThemeManager.isWindows10();
68150
}
69151

70152
public void SetDraggableControls(List<Control> controls)
@@ -87,7 +169,7 @@ protected override void OnMouseDown(MouseEventArgs e)
87169
{
88170
base.OnMouseDown(e);
89171

90-
if (draggable && e.Button == MouseButtons.Left)
172+
if (e.Button == MouseButtons.Left && draggable)
91173
{
92174
GoDrag();
93175
}

QuickLibrary/QlibMenuSeparator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public QlibMenuSeparator() { }
1010
protected override void OnPaint(PaintEventArgs e)
1111
{
1212
int y = e.ClipRectangle.Y + (e.ClipRectangle.Height / 2) - 1;
13-
e.Graphics.DrawLine(new Pen(ThemeManager.BorderColor), e.ClipRectangle.X + 4, y, e.ClipRectangle.Width - 5, y);
13+
e.Graphics.DrawLine(new Pen(ThemeManager.BorderColor), e.ClipRectangle.X + 10, y, e.ClipRectangle.Width - 11, y);
1414
}
1515
}
1616
}

QuickLibrary/QlibSizableForm.cs

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Drawing;
5+
using System.Windows.Forms;
6+
7+
namespace QuickLibrary
8+
{
9+
public class QlibSizableForm : Form
10+
{
11+
[Browsable(false), Obsolete("Don't use this! (AutoScaleMode = Dpi)", true), EditorBrowsable(EditorBrowsableState.Never)]
12+
public new enum AutoScaleMode { };
13+
14+
[Browsable(false), Obsolete("Don't use this! (HelpButton = false)", true), EditorBrowsable(EditorBrowsableState.Never)]
15+
public new enum HelpButton { };
16+
[Browsable(false), Obsolete("Don't use this! (AutoScroll = false)", true), EditorBrowsable(EditorBrowsableState.Never)]
17+
public new enum AutoScroll { };
18+
19+
[Browsable(false), Obsolete("Don't use this! (AutoScrollMargin = [0, 0])", true), EditorBrowsable(EditorBrowsableState.Never)]
20+
public new enum AutoScrollMargin { };
21+
22+
[Browsable(false), Obsolete("Don't use this! (AutoScrollMinSize = [0, 0])", true), EditorBrowsable(EditorBrowsableState.Never)]
23+
public new enum AutoScrollMinSize { };
24+
25+
[Browsable(false), Obsolete("Don't use this! (AutoSize = false)", true), EditorBrowsable(EditorBrowsableState.Never)]
26+
public new enum AutoSize { };
27+
28+
[Browsable(false), Obsolete("Don't use this! (AutoSizeMode = GrowAndShrink)", true), EditorBrowsable(EditorBrowsableState.Never)]
29+
public new enum AutoSizeMode { };
30+
31+
[Browsable(false), Obsolete("Don't use this! (BackgroundImage = None)", true), EditorBrowsable(EditorBrowsableState.Never)]
32+
public new enum BackgroundImage { };
33+
34+
[Browsable(false), Obsolete("Don't use this! (BackgroundImageLayout = Tile)", true), EditorBrowsable(EditorBrowsableState.Never)]
35+
public new enum BackgroundImageLayout { };
36+
37+
[Browsable(false), Obsolete("Don't use this! (Font = ThemeManager.DefaultFont)", true), EditorBrowsable(EditorBrowsableState.Never)]
38+
public new enum Font { };
39+
40+
public bool draggable = false;
41+
42+
public const int WS_SYSMENU = 0x80000;
43+
public const int CS_DROPSHADOW = 0x20000;
44+
45+
const int WM_NCHITTEST = 0x0084;
46+
const int HTCLIENT = 1;
47+
const int HTCAPTION = 2;
48+
49+
protected override void WndProc(ref Message m)
50+
{
51+
base.WndProc(ref m);
52+
switch (m.Msg)
53+
{
54+
case WM_NCHITTEST:
55+
if (m.Result == (IntPtr)HTCLIENT)
56+
{
57+
m.Result = (IntPtr)HTCAPTION;
58+
}
59+
break;
60+
}
61+
}
62+
63+
protected override CreateParams CreateParams
64+
{
65+
get
66+
{
67+
CreateParams cp = base.CreateParams;
68+
cp.Style |= 0x40000;
69+
return cp;
70+
}
71+
}
72+
73+
74+
//protected override CreateParams CreateParams
75+
//{
76+
// get
77+
// {
78+
// CreateParams cp = base.CreateParams;
79+
// cp.ClassStyle |= 0x20000;
80+
// return cp;
81+
// }
82+
//}
83+
84+
//protected override void WndProc(ref Message m)
85+
//{
86+
// const int RESIZE_HANDLE_SIZE = 10;
87+
88+
// switch (m.Msg)
89+
// {
90+
// case 0x0084/*NCHITTEST*/ :
91+
// base.WndProc(ref m);
92+
93+
// if ((int)m.Result == 0x01/*HTCLIENT*/)
94+
// {
95+
// Point screenPoint = new Point(m.LParam.ToInt32());
96+
// Point clientPoint = this.PointToClient(screenPoint);
97+
// if (clientPoint.Y <= RESIZE_HANDLE_SIZE)
98+
// {
99+
// if (clientPoint.X <= RESIZE_HANDLE_SIZE)
100+
// m.Result = (IntPtr)13/*HTTOPLEFT*/ ;
101+
// else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
102+
// m.Result = (IntPtr)12/*HTTOP*/ ;
103+
// else
104+
// m.Result = (IntPtr)14/*HTTOPRIGHT*/ ;
105+
// }
106+
// else if (clientPoint.Y <= (Size.Height - RESIZE_HANDLE_SIZE))
107+
// {
108+
// if (clientPoint.X <= RESIZE_HANDLE_SIZE)
109+
// m.Result = (IntPtr)10/*HTLEFT*/ ;
110+
// else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
111+
// m.Result = (IntPtr)2/*HTCAPTION*/ ;
112+
// else
113+
// m.Result = (IntPtr)11/*HTRIGHT*/ ;
114+
// }
115+
// else
116+
// {
117+
// if (clientPoint.X <= RESIZE_HANDLE_SIZE)
118+
// m.Result = (IntPtr)16/*HTBOTTOMLEFT*/ ;
119+
// else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
120+
// m.Result = (IntPtr)15/*HTBOTTOM*/ ;
121+
// else
122+
// m.Result = (IntPtr)17/*HTBOTTOMRIGHT*/ ;
123+
// }
124+
// }
125+
// return;
126+
// }
127+
// base.WndProc(ref m);
128+
//}
129+
130+
public QlibSizableForm()
131+
{
132+
base.FormBorderStyle = FormBorderStyle.Sizable;
133+
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
134+
base.HelpButton = false;
135+
base.AutoScroll = false;
136+
base.AutoScrollMargin = new Size(0, 0);
137+
base.AutoScrollMinSize = new Size(0, 0);
138+
base.AutoSize = false;
139+
base.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
140+
base.BackgroundImage = null;
141+
base.BackgroundImageLayout = ImageLayout.Tile;
142+
base.Font = ThemeManager.DefaultFont;
143+
144+
this.Load += QlibSizableForm_Load;
145+
}
146+
147+
private void QlibSizableForm_Load(object sender, EventArgs e)
148+
{
149+
this.FormBorderStyle = FormBorderStyle.None;
150+
}
151+
152+
public void SetDraggableControls(List<Control> controls)
153+
{
154+
foreach (Control control in controls)
155+
{
156+
control.MouseDown += Control_MouseDown;
157+
}
158+
}
159+
160+
private void Control_MouseDown(object sender, MouseEventArgs e)
161+
{
162+
if (e.Button == MouseButtons.Left)
163+
{
164+
GoDrag();
165+
}
166+
}
167+
168+
protected override void OnMouseDown(MouseEventArgs e)
169+
{
170+
base.OnMouseDown(e);
171+
172+
if (e.Button == MouseButtons.Left && draggable)
173+
{
174+
GoDrag();
175+
}
176+
}
177+
178+
private void GoDrag()
179+
{
180+
Cursor.Current = Cursors.SizeAll;
181+
NativeMethodsManager.ReleaseCapture();
182+
NativeMethodsManager.SendMessage(Handle, 0xA1, 0x2, 0);
183+
}
184+
}
185+
}

0 commit comments

Comments
 (0)