|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.ComponentModel; |
| 4 | +using System.Windows.Forms; |
| 5 | + |
| 6 | +namespace QuickLibrary |
| 7 | +{ |
| 8 | + public class QlibFixedForm : Form |
| 9 | + { |
| 10 | + public bool draggable = false; |
| 11 | + |
| 12 | + [Browsable(false), Obsolete("Don't use this! (FormBorderStyle = None)", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 13 | + public new enum FormBorderStyle { }; |
| 14 | + |
| 15 | + [Browsable(false), Obsolete("Don't use this! (AutoScaleMode = Dpi)", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 16 | + public new enum AutoScaleMode { }; |
| 17 | + |
| 18 | + [Browsable(false), Obsolete("Don't use this! (HelpButton = false)", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 19 | + public new enum HelpButton { }; |
| 20 | + [Browsable(false), Obsolete("Don't use this! (AutoScroll = false)", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 21 | + public new enum AutoScroll { }; |
| 22 | + |
| 23 | + [Browsable(false), Obsolete("Don't use this! (AutoScrollMargin = [0, 0])", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 24 | + public new enum AutoScrollMargin { }; |
| 25 | + |
| 26 | + [Browsable(false), Obsolete("Don't use this! (AutoScrollMinSize = [0, 0])", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 27 | + public new enum AutoScrollMinSize { }; |
| 28 | + |
| 29 | + [Browsable(false), Obsolete("Don't use this! (AutoSize = false)", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 30 | + public new enum AutoSize { }; |
| 31 | + |
| 32 | + [Browsable(false), Obsolete("Don't use this! (AutoSizeMode = GrowAndShrink)", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 33 | + public new enum AutoSizeMode { }; |
| 34 | + |
| 35 | + [Browsable(false), Obsolete("Don't use this! (BackgroundImage = None)", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 36 | + public new enum BackgroundImage { }; |
| 37 | + |
| 38 | + [Browsable(false), Obsolete("Don't use this! (BackgroundImageLayout = Tile)", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 39 | + public new enum BackgroundImageLayout { }; |
| 40 | + |
| 41 | + [Browsable(false), Obsolete("Don't use this! (Font = ThemeManager.DefaultFont)", true), EditorBrowsable(EditorBrowsableState.Never)] |
| 42 | + public new enum Font { }; |
| 43 | + |
| 44 | + protected override CreateParams CreateParams |
| 45 | + { |
| 46 | + get |
| 47 | + { |
| 48 | + const int CS_DROPSHADOW = 0x20000; |
| 49 | + CreateParams cp = base.CreateParams; |
| 50 | + cp.ClassStyle |= CS_DROPSHADOW; |
| 51 | + return cp; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + public QlibFixedForm() |
| 56 | + { |
| 57 | + base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; |
| 58 | + base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; |
| 59 | + base.HelpButton = false; |
| 60 | + base.AutoScroll = false; |
| 61 | + base.AutoScrollMargin = new System.Drawing.Size(0, 0); |
| 62 | + base.AutoScrollMinSize = new System.Drawing.Size(0, 0); |
| 63 | + base.AutoSize = false; |
| 64 | + base.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; |
| 65 | + base.BackgroundImage = null; |
| 66 | + base.BackgroundImageLayout = ImageLayout.Tile; |
| 67 | + base.Font = ThemeManager.DefaultFont; |
| 68 | + } |
| 69 | + |
| 70 | + public void SetDraggableControls(List<Control> controls) |
| 71 | + { |
| 72 | + foreach (Control control in controls) |
| 73 | + { |
| 74 | + control.MouseDown += Control_MouseDown; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + private void Control_MouseDown(object sender, MouseEventArgs e) |
| 79 | + { |
| 80 | + if (e.Button == MouseButtons.Left) |
| 81 | + { |
| 82 | + GoDrag(); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + protected override void OnMouseDown(MouseEventArgs e) |
| 87 | + { |
| 88 | + base.OnMouseDown(e); |
| 89 | + |
| 90 | + if (draggable && e.Button == MouseButtons.Left) |
| 91 | + { |
| 92 | + GoDrag(); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + private void GoDrag() |
| 97 | + { |
| 98 | + Cursor.Current = Cursors.SizeAll; |
| 99 | + NativeMethodsManager.ReleaseCapture(); |
| 100 | + NativeMethodsManager.SendMessage(Handle, 0xA1, 0x2, 0); |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments