|
| 1 | +using System; |
| 2 | +using System.ComponentModel; |
| 3 | +using System.Drawing; |
| 4 | +using System.Windows.Forms; |
| 5 | + |
| 6 | +namespace QuickLibrary |
| 7 | +{ |
| 8 | + public class QlibContextMenuStrip : ContextMenuStrip |
| 9 | + { |
| 10 | + #region PRIVATE PROPS |
| 11 | + |
| 12 | + private bool darkMode = false; |
| 13 | + |
| 14 | + #endregion |
| 15 | + |
| 16 | + #region HIDDEN PROPS |
| 17 | + |
| 18 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 19 | + public new Font Font { get { return base.Font; } set { } } |
| 20 | + |
| 21 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 22 | + public new Color ForeColor { get { return base.ForeColor; } set { } } |
| 23 | + |
| 24 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 25 | + public new Color BackColor { get { return base.BackColor; } set { } } |
| 26 | + |
| 27 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 28 | + public new Image BackgroundImage { get { return base.BackgroundImage; } set { } } |
| 29 | + |
| 30 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 31 | + public new ImageLayout BackgroundImageLayout { get { return base.BackgroundImageLayout; } set { } } |
| 32 | + |
| 33 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 34 | + public new RightToLeft RightToLeft { get { return base.RightToLeft; } set { } } |
| 35 | + |
| 36 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 37 | + public new string Text { get { return base.Text; } set { } } |
| 38 | + |
| 39 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 40 | + public new bool AllowDrop { get { return base.AllowDrop; } set { } } |
| 41 | + |
| 42 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 43 | + public new bool AutoSize { get { return base.AutoSize; } set { } } |
| 44 | + |
| 45 | + [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] |
| 46 | + public new Padding Padding { get { return base.Padding; } set { } } |
| 47 | + |
| 48 | + #endregion |
| 49 | + |
| 50 | + #region PUBLIC PROPS |
| 51 | + |
| 52 | + [Category("Qlib props"), Browsable(true), Description("Dark mode")] |
| 53 | + public bool DarkMode |
| 54 | + { |
| 55 | + get { return darkMode; } |
| 56 | + set { SetDarkMode(value); } |
| 57 | + } |
| 58 | + |
| 59 | + #endregion |
| 60 | + |
| 61 | + #region CONSTRUCTOR |
| 62 | + |
| 63 | + public QlibContextMenuStrip(IContainer components) : base(components) |
| 64 | + { |
| 65 | + base.Font = ThemeMan.DefaultFont; |
| 66 | + base.ForeColor = Color.Black; |
| 67 | + base.BackColor = ThemeMan.LightSecondColor; |
| 68 | + base.BackgroundImage = null; |
| 69 | + base.BackgroundImageLayout = ImageLayout.Tile; |
| 70 | + base.RightToLeft = RightToLeft.No; |
| 71 | + base.Text = null; |
| 72 | + base.AllowDrop = false; |
| 73 | + base.AutoSize = true; |
| 74 | + base.Padding = new Padding(32, 2, 2, 2); |
| 75 | + } |
| 76 | + |
| 77 | + #endregion |
| 78 | + |
| 79 | + #region PRIVATE BODY |
| 80 | + |
| 81 | + private void SetDarkMode(bool dark) |
| 82 | + { |
| 83 | + darkMode = dark; |
| 84 | + |
| 85 | + if (dark) |
| 86 | + { |
| 87 | + base.BackColor = ThemeMan.DarkSecondColor; |
| 88 | + } |
| 89 | + else |
| 90 | + { |
| 91 | + base.BackColor = ThemeMan.LightSecondColor; |
| 92 | + } |
| 93 | + |
| 94 | + foreach (var c in Items) |
| 95 | + { |
| 96 | + if (c.GetType() == typeof(ToolStripMenuItem)) |
| 97 | + { |
| 98 | + if (dark) |
| 99 | + { |
| 100 | + (c as ToolStripMenuItem).BackColor = ThemeMan.DarkSecondColor; |
| 101 | + (c as ToolStripMenuItem).ForeColor = Color.White; |
| 102 | + (c as ToolStripMenuItem).DropDown.BackColor = ThemeMan.DarkSecondColor; |
| 103 | + (c as ToolStripMenuItem).DropDown.ForeColor = Color.White; |
| 104 | + } |
| 105 | + else |
| 106 | + { |
| 107 | + (c as ToolStripMenuItem).BackColor = ThemeMan.LightSecondColor; |
| 108 | + (c as ToolStripMenuItem).ForeColor = Color.Black; |
| 109 | + (c as ToolStripMenuItem).DropDown.BackColor = ThemeMan.LightSecondColor; |
| 110 | + (c as ToolStripMenuItem).DropDown.ForeColor = Color.Black; |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + Renderer = new CustomToolStripSystemRenderer(dark); |
| 116 | + } |
| 117 | + |
| 118 | + #endregion |
| 119 | + } |
| 120 | +} |
0 commit comments