|
| 1 | +using System; |
| 2 | +using System.ComponentModel; |
| 3 | +using System.Drawing; |
| 4 | +using System.Drawing.Drawing2D; |
| 5 | +using System.Drawing.Text; |
| 6 | +using System.Windows.Forms; |
| 7 | + |
| 8 | +namespace QuickLibrary |
| 9 | +{ |
| 10 | + public class QlibRadio : RadioButton |
| 11 | + { |
| 12 | + // PRIVATE FIELDS |
| 13 | + |
| 14 | + private bool darkMode = false; |
| 15 | + private bool hovered = false; |
| 16 | + private bool pressed = false; |
| 17 | + |
| 18 | + // HIDDEN PROPS |
| 19 | + |
| 20 | + [Browsable(false)] |
| 21 | + public new Appearance Appearance => base.Appearance; |
| 22 | + |
| 23 | + [Browsable(false)] |
| 24 | + public new Color ForeColor => base.ForeColor; |
| 25 | + |
| 26 | + [Browsable(false)] |
| 27 | + public new Color BackColor => base.BackColor; |
| 28 | + |
| 29 | + [Browsable(false)] |
| 30 | + public new Image BackgroundImage => base.BackgroundImage; |
| 31 | + |
| 32 | + [Browsable(false)] |
| 33 | + public new ImageLayout BackgroundImageLayout => base.BackgroundImageLayout; |
| 34 | + |
| 35 | + [Browsable(false)] |
| 36 | + public new ContentAlignment CheckAlign => base.CheckAlign; |
| 37 | + |
| 38 | + [Browsable(false)] |
| 39 | + public new Image Image => base.Image; |
| 40 | + |
| 41 | + [Browsable(false)] |
| 42 | + public new Cursor Cursor => base.Cursor; |
| 43 | + |
| 44 | + [Browsable(false)] |
| 45 | + public new FlatButtonAppearance FlatAppearance => base.FlatAppearance; |
| 46 | + |
| 47 | + [Browsable(false)] |
| 48 | + public new FlatStyle FlatStyle => base.FlatStyle; |
| 49 | + |
| 50 | + [Browsable(false)] |
| 51 | + public new ContentAlignment ImageAlign => base.ImageAlign; |
| 52 | + |
| 53 | + [Browsable(false)] |
| 54 | + public new int ImageIndex => base.ImageIndex; |
| 55 | + |
| 56 | + [Browsable(false)] |
| 57 | + public new string ImageKey => base.ImageKey; |
| 58 | + |
| 59 | + [Browsable(false)] |
| 60 | + public new Padding Padding => base.Padding; |
| 61 | + |
| 62 | + [Browsable(false)] |
| 63 | + public new RightToLeft RightToLeft => base.RightToLeft; |
| 64 | + |
| 65 | + [Browsable(false)] |
| 66 | + public new bool AutoSize => base.AutoSize; |
| 67 | + |
| 68 | + [Browsable(false)] |
| 69 | + public new DockStyle Dock => base.Dock; |
| 70 | + |
| 71 | + [Browsable(false)] |
| 72 | + public new Size MinimumSize => base.MinimumSize; |
| 73 | + |
| 74 | + [Browsable(false)] |
| 75 | + public new Size MaximumSize => base.MaximumSize; |
| 76 | + |
| 77 | + [Browsable(false)] |
| 78 | + public new bool AutoCheck => base.AutoCheck; |
| 79 | + |
| 80 | + // PUBLIC PROPS |
| 81 | + |
| 82 | + [Category("Qlib props"), Browsable(true), Description("Dark mode")] |
| 83 | + public bool DarkMode |
| 84 | + { |
| 85 | + get { return darkMode; } |
| 86 | + set { SetDarkMode(value); } |
| 87 | + } |
| 88 | + |
| 89 | + // CONSTRUCTOR |
| 90 | + |
| 91 | + public QlibRadio() |
| 92 | + { |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + // PRIVATE BODY |
| 97 | + |
| 98 | + private void CustomCheckBox_MouseUp(object sender, MouseEventArgs e) |
| 99 | + { |
| 100 | + pressed = false; |
| 101 | + Refresh(); |
| 102 | + } |
| 103 | + |
| 104 | + private void CustomCheckBox_MouseDown(object sender, MouseEventArgs e) |
| 105 | + { |
| 106 | + pressed = true; |
| 107 | + Refresh(); |
| 108 | + } |
| 109 | + |
| 110 | + private void CustomCheckBox_MouseLeave(object sender, EventArgs e) |
| 111 | + { |
| 112 | + hovered = false; |
| 113 | + Refresh(); |
| 114 | + } |
| 115 | + |
| 116 | + private void CustomCheckBox_MouseEnter(object sender, EventArgs e) |
| 117 | + { |
| 118 | + hovered = true; |
| 119 | + Refresh(); |
| 120 | + } |
| 121 | + |
| 122 | + private void SetDarkMode(bool dark) |
| 123 | + { |
| 124 | + darkMode = dark; |
| 125 | + |
| 126 | + if (dark) |
| 127 | + { |
| 128 | + base.BackColor = ThemeManager.DarkBackColor; |
| 129 | + base.ForeColor = Color.White; |
| 130 | + |
| 131 | + SetStyle(ControlStyles.UserPaint, true); |
| 132 | + SetStyle(ControlStyles.AllPaintingInWmPaint, true); |
| 133 | + |
| 134 | + MouseEnter += CustomCheckBox_MouseEnter; |
| 135 | + MouseLeave += CustomCheckBox_MouseLeave; |
| 136 | + MouseDown += CustomCheckBox_MouseDown; |
| 137 | + MouseUp += CustomCheckBox_MouseUp; |
| 138 | + } |
| 139 | + else |
| 140 | + { |
| 141 | + base.BackColor = ThemeManager.LightBackColor; |
| 142 | + base.ForeColor = Color.Black; |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + protected override void OnPaint(PaintEventArgs e) |
| 147 | + { |
| 148 | + if (darkMode) |
| 149 | + { |
| 150 | + int top = (Height / 2) - 8; |
| 151 | + |
| 152 | + e.Graphics.Clear(ThemeManager.DarkBackColor); |
| 153 | + |
| 154 | + e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; |
| 155 | + |
| 156 | + if (pressed) |
| 157 | + { |
| 158 | + e.Graphics.FillEllipse(new SolidBrush(ThemeManager.PressedColor), new Rectangle(0, top + 2, 15, 15)); |
| 159 | + } |
| 160 | + else |
| 161 | + { |
| 162 | + if (hovered) |
| 163 | + { |
| 164 | + e.Graphics.FillEllipse(new SolidBrush(ThemeManager.DarkHoverColor), new Rectangle(0, top + 2, 15, 15)); |
| 165 | + } |
| 166 | + else |
| 167 | + { |
| 168 | + e.Graphics.FillEllipse(new SolidBrush(ThemeManager.DarkSecondColor), new Rectangle(0, top + 2, 15, 15)); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + if (Focused) |
| 173 | + { |
| 174 | + e.Graphics.DrawEllipse(new Pen(ThemeManager.BorderColor, 2), new Rectangle(1, top + 3, 13, 13)); |
| 175 | + } |
| 176 | + |
| 177 | + if (Checked) |
| 178 | + { |
| 179 | + if (Enabled) |
| 180 | + { |
| 181 | + e.Graphics.FillEllipse(new SolidBrush(ForeColor), new Rectangle(4, top + 6, 7, 7)); |
| 182 | + } |
| 183 | + else |
| 184 | + { |
| 185 | + e.Graphics.FillEllipse(new SolidBrush(ThemeManager.BorderColor), new Rectangle(4, top + 6, 7, 7)); |
| 186 | + } |
| 187 | + } |
| 188 | + |
| 189 | + e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; |
| 190 | + if (Enabled) |
| 191 | + { |
| 192 | + e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), 22, top); |
| 193 | + } |
| 194 | + else |
| 195 | + { |
| 196 | + e.Graphics.DrawString(Text, Font, new SolidBrush(ThemeManager.BorderColor), 22, top); |
| 197 | + } |
| 198 | + } |
| 199 | + else |
| 200 | + { |
| 201 | + base.OnPaint(e); |
| 202 | + } |
| 203 | + } |
| 204 | + } |
| 205 | +} |
0 commit comments