SHOW:
|
|
- or go back to the newest paste.
| 1 | #region Imports | |
| 2 | ||
| 3 | using System; | |
| 4 | using System.Drawing; | |
| 5 | using System.Windows.Forms; | |
| 6 | using System.Drawing.Drawing2D; | |
| 7 | using System.ComponentModel; | |
| 8 | ||
| 9 | #endregion | |
| 10 | ||
| 11 | //|------DO-NOT-REMOVE------| | |
| 12 | // | |
| 13 | // Creator: HazelDev | |
| 14 | // Site : HazelDev.com | |
| 15 | // Created: 20.Sep.2014 | |
| 16 | // Changed: 24.Jan.2015 | |
| 17 | // Version: 1.2.0 | |
| 18 | // | |
| 19 | //|------DO-NOT-REMOVE------| | |
| 20 | ||
| 21 | namespace MonoFlat | |
| 22 | {
| |
| 23 | ||
| 24 | #region RoundRectangle | |
| 25 | ||
| 26 | sealed class RoundRectangle | |
| 27 | {
| |
| 28 | public static GraphicsPath RoundRect(Rectangle Rectangle, int Curve) | |
| 29 | {
| |
| 30 | GraphicsPath P = new GraphicsPath(); | |
| 31 | int ArcRectangleWidth = Curve * 2; | |
| 32 | P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90); | |
| 33 | P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90); | |
| 34 | P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90); | |
| 35 | P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90); | |
| 36 | P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y)); | |
| 37 | return P; | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | #endregion | |
| 42 | ||
| 43 | #region ThemeContainer | |
| 44 | ||
| 45 | public class MonoFlat_ThemeContainer : ContainerControl | |
| 46 | {
| |
| 47 | ||
| 48 | #region Enums | |
| 49 | ||
| 50 | public enum MouseState | |
| 51 | {
| |
| 52 | None = 0, | |
| 53 | Over = 1, | |
| 54 | Down = 2, | |
| 55 | Block = 3 | |
| 56 | } | |
| 57 | ||
| 58 | #endregion | |
| 59 | #region Variables | |
| 60 | ||
| 61 | private Rectangle HeaderRect; | |
| 62 | protected MouseState State; | |
| 63 | private int MoveHeight; | |
| 64 | private Point MouseP = new Point(0, 0); | |
| 65 | private bool Cap = false; | |
| 66 | private bool HasShown; | |
| 67 | ||
| 68 | #endregion | |
| 69 | #region Properties | |
| 70 | ||
| 71 | private bool _Sizable = true; | |
| 72 | public bool Sizable | |
| 73 | {
| |
| 74 | get | |
| 75 | {
| |
| 76 | return _Sizable; | |
| 77 | } | |
| 78 | set | |
| 79 | {
| |
| 80 | _Sizable = value; | |
| 81 | } | |
| 82 | } | |
| 83 | ||
| 84 | private bool _SmartBounds = true; | |
| 85 | public bool SmartBounds | |
| 86 | {
| |
| 87 | get | |
| 88 | {
| |
| 89 | return _SmartBounds; | |
| 90 | } | |
| 91 | set | |
| 92 | {
| |
| 93 | _SmartBounds = value; | |
| 94 | } | |
| 95 | } | |
| 96 | ||
| 97 | private bool _RoundCorners = true; | |
| 98 | public bool RoundCorners | |
| 99 | {
| |
| 100 | get | |
| 101 | {
| |
| 102 | return _RoundCorners; | |
| 103 | } | |
| 104 | set | |
| 105 | {
| |
| 106 | _RoundCorners = value; | |
| 107 | Invalidate(); | |
| 108 | } | |
| 109 | } | |
| 110 | ||
| 111 | private bool _IsParentForm; | |
| 112 | protected bool IsParentForm | |
| 113 | {
| |
| 114 | get | |
| 115 | {
| |
| 116 | return _IsParentForm; | |
| 117 | } | |
| 118 | } | |
| 119 | ||
| 120 | protected bool IsParentMdi | |
| 121 | {
| |
| 122 | get | |
| 123 | {
| |
| 124 | if (Parent == null) | |
| 125 | {
| |
| 126 | return false; | |
| 127 | } | |
| 128 | return Parent.Parent != null; | |
| 129 | } | |
| 130 | } | |
| 131 | ||
| 132 | private bool _ControlMode; | |
| 133 | protected bool ControlMode | |
| 134 | {
| |
| 135 | get | |
| 136 | {
| |
| 137 | return _ControlMode; | |
| 138 | } | |
| 139 | set | |
| 140 | {
| |
| 141 | _ControlMode = value; | |
| 142 | Invalidate(); | |
| 143 | } | |
| 144 | } | |
| 145 | ||
| 146 | private FormStartPosition _StartPosition; | |
| 147 | public FormStartPosition StartPosition | |
| 148 | {
| |
| 149 | get | |
| 150 | {
| |
| 151 | if (_IsParentForm && !_ControlMode) | |
| 152 | {
| |
| 153 | return ParentForm.StartPosition; | |
| 154 | } | |
| 155 | else | |
| 156 | {
| |
| 157 | return _StartPosition; | |
| 158 | } | |
| 159 | } | |
| 160 | set | |
| 161 | {
| |
| 162 | _StartPosition = value; | |
| 163 | ||
| 164 | if (_IsParentForm && !_ControlMode) | |
| 165 | {
| |
| 166 | ParentForm.StartPosition = value; | |
| 167 | } | |
| 168 | } | |
| 169 | } | |
| 170 | ||
| 171 | #endregion | |
| 172 | #region EventArgs | |
| 173 | ||
| 174 | protected sealed override void OnParentChanged(EventArgs e) | |
| 175 | {
| |
| 176 | base.OnParentChanged(e); | |
| 177 | ||
| 178 | if (Parent == null) | |
| 179 | {
| |
| 180 | return; | |
| 181 | } | |
| 182 | _IsParentForm = Parent is Form; | |
| 183 | ||
| 184 | if (!_ControlMode) | |
| 185 | {
| |
| 186 | InitializeMessages(); | |
| 187 | ||
| 188 | if (_IsParentForm) | |
| 189 | {
| |
| 190 | this.ParentForm.FormBorderStyle = FormBorderStyle.None; | |
| 191 | this.ParentForm.TransparencyKey = Color.Fuchsia; | |
| 192 | ||
| 193 | if (!DesignMode) | |
| 194 | {
| |
| 195 | ParentForm.Shown += FormShown; | |
| 196 | } | |
| 197 | } | |
| 198 | Parent.BackColor = BackColor; | |
| 199 | // Parent.MinimumSize = New Size(261, 65) | |
| 200 | } | |
| 201 | } | |
| 202 | ||
| 203 | protected sealed override void OnSizeChanged(EventArgs e) | |
| 204 | {
| |
| 205 | base.OnSizeChanged(e); | |
| 206 | if (!_ControlMode) | |
| 207 | {
| |
| 208 | HeaderRect = new Rectangle(0, 0, Width - 14, MoveHeight - 7); | |
| 209 | } | |
| 210 | Invalidate(); | |
| 211 | } | |
| 212 | ||
| 213 | protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) | |
| 214 | {
| |
| 215 | base.OnMouseDown(e); | |
| 216 | Focus(); | |
| 217 | if (e.Button == MouseButtons.Left) | |
| 218 | {
| |
| 219 | SetState(MouseState.Down); | |
| 220 | } | |
| 221 | if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized || _ControlMode)) | |
| 222 | {
| |
| 223 | if (HeaderRect.Contains(e.Location)) | |
| 224 | {
| |
| 225 | Capture = false; | |
| 226 | WM_LMBUTTONDOWN = true; | |
| 227 | DefWndProc(ref Messages[0]); | |
| 228 | } | |
| 229 | else if (_Sizable && !(Previous == 0)) | |
| 230 | {
| |
| 231 | Capture = false; | |
| 232 | WM_LMBUTTONDOWN = true; | |
| 233 | DefWndProc(ref Messages[Previous]); | |
| 234 | } | |
| 235 | } | |
| 236 | } | |
| 237 | ||
| 238 | protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) | |
| 239 | {
| |
| 240 | base.OnMouseUp(e); | |
| 241 | Cap = false; | |
| 242 | } | |
| 243 | ||
| 244 | protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) | |
| 245 | {
| |
| 246 | base.OnMouseMove(e); | |
| 247 | if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized)) | |
| 248 | {
| |
| 249 | if (_Sizable && !_ControlMode) | |
| 250 | {
| |
| 251 | InvalidateMouse(); | |
| 252 | } | |
| 253 | } | |
| 254 | if (Cap) | |
| 255 | {
| |
| 256 | Parent.Location = (System.Drawing.Point)((object)(System.Convert.ToDouble(MousePosition) - System.Convert.ToDouble(MouseP))); | |
| 257 | } | |
| 258 | } | |
| 259 | ||
| 260 | protected override void OnInvalidated(System.Windows.Forms.InvalidateEventArgs e) | |
| 261 | {
| |
| 262 | base.OnInvalidated(e); | |
| 263 | ParentForm.Text = Text; | |
| 264 | } | |
| 265 | ||
| 266 | protected override void OnPaintBackground(PaintEventArgs e) | |
| 267 | {
| |
| 268 | base.OnPaintBackground(e); | |
| 269 | } | |
| 270 | ||
| 271 | protected override void OnTextChanged(System.EventArgs e) | |
| 272 | {
| |
| 273 | base.OnTextChanged(e); | |
| 274 | Invalidate(); | |
| 275 | } | |
| 276 | ||
| 277 | private void FormShown(object sender, EventArgs e) | |
| 278 | {
| |
| 279 | if (_ControlMode || HasShown) | |
| 280 | {
| |
| 281 | return; | |
| 282 | } | |
| 283 | ||
| 284 | if (_StartPosition == FormStartPosition.CenterParent || _StartPosition == FormStartPosition.CenterScreen) | |
| 285 | {
| |
| 286 | Rectangle SB = Screen.PrimaryScreen.Bounds; | |
| 287 | Rectangle CB = ParentForm.Bounds; | |
| 288 | ParentForm.Location = new Point(SB.Width / 2 - CB.Width / 2, SB.Height / 2 - CB.Width / 2); | |
| 289 | } | |
| 290 | HasShown = true; | |
| 291 | } | |
| 292 | ||
| 293 | #endregion | |
| 294 | #region Mouse & Size | |
| 295 | ||
| 296 | private void SetState(MouseState current) | |
| 297 | {
| |
| 298 | State = current; | |
| 299 | Invalidate(); | |
| 300 | } | |
| 301 | ||
| 302 | private Point GetIndexPoint; | |
| 303 | private bool B1x; | |
| 304 | private bool B2x; | |
| 305 | private bool B3; | |
| 306 | private bool B4; | |
| 307 | private int GetIndex() | |
| 308 | {
| |
| 309 | GetIndexPoint = PointToClient(MousePosition); | |
| 310 | B1x = GetIndexPoint.X < 7; | |
| 311 | B2x = GetIndexPoint.X > Width - 7; | |
| 312 | B3 = GetIndexPoint.Y < 7; | |
| 313 | B4 = GetIndexPoint.Y > Height - 7; | |
| 314 | ||
| 315 | if (B1x && B3) | |
| 316 | {
| |
| 317 | return 4; | |
| 318 | } | |
| 319 | if (B1x && B4) | |
| 320 | {
| |
| 321 | return 7; | |
| 322 | } | |
| 323 | if (B2x && B3) | |
| 324 | {
| |
| 325 | return 5; | |
| 326 | } | |
| 327 | if (B2x && B4) | |
| 328 | {
| |
| 329 | return 8; | |
| 330 | } | |
| 331 | if (B1x) | |
| 332 | {
| |
| 333 | return 1; | |
| 334 | } | |
| 335 | if (B2x) | |
| 336 | {
| |
| 337 | return 2; | |
| 338 | } | |
| 339 | if (B3) | |
| 340 | {
| |
| 341 | return 3; | |
| 342 | } | |
| 343 | if (B4) | |
| 344 | {
| |
| 345 | return 6; | |
| 346 | } | |
| 347 | return 0; | |
| 348 | } | |
| 349 | ||
| 350 | private int Current; | |
| 351 | private int Previous; | |
| 352 | private void InvalidateMouse() | |
| 353 | {
| |
| 354 | Current = GetIndex(); | |
| 355 | if (Current == Previous) | |
| 356 | {
| |
| 357 | return; | |
| 358 | } | |
| 359 | ||
| 360 | Previous = Current; | |
| 361 | switch (Previous) | |
| 362 | {
| |
| 363 | case 0: | |
| 364 | Cursor = Cursors.Default; | |
| 365 | break; | |
| 366 | case 6: | |
| 367 | Cursor = Cursors.SizeNS; | |
| 368 | break; | |
| 369 | case 8: | |
| 370 | Cursor = Cursors.SizeNWSE; | |
| 371 | break; | |
| 372 | case 7: | |
| 373 | Cursor = Cursors.SizeNESW; | |
| 374 | break; | |
| 375 | } | |
| 376 | } | |
| 377 | ||
| 378 | private Message[] Messages = new Message[9]; | |
| 379 | private void InitializeMessages() | |
| 380 | {
| |
| 381 | Messages[0] = Message.Create(Parent.Handle, 161, new IntPtr(2), IntPtr.Zero); | |
| 382 | for (int I = 1; I <= 8; I++) | |
| 383 | {
| |
| 384 | Messages[I] = Message.Create(Parent.Handle, 161, new IntPtr(I + 9), IntPtr.Zero); | |
| 385 | } | |
| 386 | } | |
| 387 | ||
| 388 | private void CorrectBounds(Rectangle bounds) | |
| 389 | {
| |
| 390 | if (Parent.Width > bounds.Width) | |
| 391 | {
| |
| 392 | Parent.Width = bounds.Width; | |
| 393 | } | |
| 394 | if (Parent.Height > bounds.Height) | |
| 395 | {
| |
| 396 | Parent.Height = bounds.Height; | |
| 397 | } | |
| 398 | ||
| 399 | int X = Parent.Location.X; | |
| 400 | int Y = Parent.Location.Y; | |
| 401 | ||
| 402 | if (X < bounds.X) | |
| 403 | {
| |
| 404 | X = bounds.X; | |
| 405 | } | |
| 406 | if (Y < bounds.Y) | |
| 407 | {
| |
| 408 | Y = bounds.Y; | |
| 409 | } | |
| 410 | ||
| 411 | int Width = bounds.X + bounds.Width; | |
| 412 | int Height = bounds.Y + bounds.Height; | |
| 413 | ||
| 414 | if (X + Parent.Width > Width) | |
| 415 | {
| |
| 416 | X = Width - Parent.Width; | |
| 417 | } | |
| 418 | if (Y + Parent.Height > Height) | |
| 419 | {
| |
| 420 | Y = Height - Parent.Height; | |
| 421 | } | |
| 422 | ||
| 423 | Parent.Location = new Point(X, Y); | |
| 424 | } | |
| 425 | ||
| 426 | private bool WM_LMBUTTONDOWN; | |
| 427 | protected override void WndProc(ref Message m) | |
| 428 | {
| |
| 429 | base.WndProc(ref m); | |
| 430 | ||
| 431 | if (WM_LMBUTTONDOWN && m.Msg == 513) | |
| 432 | {
| |
| 433 | WM_LMBUTTONDOWN = false; | |
| 434 | ||
| 435 | SetState(MouseState.Over); | |
| 436 | if (!_SmartBounds) | |
| 437 | {
| |
| 438 | return; | |
| 439 | } | |
| 440 | ||
| 441 | if (IsParentMdi) | |
| 442 | {
| |
| 443 | CorrectBounds(new Rectangle(Point.Empty, Parent.Parent.Size)); | |
| 444 | } | |
| 445 | else | |
| 446 | {
| |
| 447 | CorrectBounds(Screen.FromControl(Parent).WorkingArea); | |
| 448 | } | |
| 449 | } | |
| 450 | } | |
| 451 | ||
| 452 | #endregion | |
| 453 | ||
| 454 | protected override void CreateHandle() | |
| 455 | {
| |
| 456 | base.CreateHandle(); | |
| 457 | } | |
| 458 | ||
| 459 | public MonoFlat_ThemeContainer() | |
| 460 | {
| |
| 461 | SetStyle((ControlStyles)(139270), true); | |
| 462 | BackColor = Color.FromArgb(32, 41, 50); | |
| 463 | Padding = new Padding(10, 70, 10, 9); | |
| 464 | DoubleBuffered = true; | |
| 465 | Dock = DockStyle.Fill; | |
| 466 | MoveHeight = 66; | |
| 467 | Font = new Font("Segoe UI", 9);
| |
| 468 | } | |
| 469 | ||
| 470 | protected override void OnPaint(PaintEventArgs e) | |
| 471 | {
| |
| 472 | base.OnPaint(e); | |
| 473 | Graphics G = e.Graphics; | |
| 474 | ||
| 475 | G.Clear(Color.FromArgb(32, 41, 50)); | |
| 476 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), new Rectangle(0, 0, Width, 60)); | |
| 477 | ||
| 478 | if (_RoundCorners == true) | |
| 479 | {
| |
| 480 | // Draw Left upper corner | |
| 481 | G.FillRectangle(Brushes.Fuchsia, 0, 0, 1, 1); | |
| 482 | G.FillRectangle(Brushes.Fuchsia, 1, 0, 1, 1); | |
| 483 | G.FillRectangle(Brushes.Fuchsia, 2, 0, 1, 1); | |
| 484 | G.FillRectangle(Brushes.Fuchsia, 3, 0, 1, 1); | |
| 485 | G.FillRectangle(Brushes.Fuchsia, 0, 1, 1, 1); | |
| 486 | G.FillRectangle(Brushes.Fuchsia, 0, 2, 1, 1); | |
| 487 | G.FillRectangle(Brushes.Fuchsia, 0, 3, 1, 1); | |
| 488 | G.FillRectangle(Brushes.Fuchsia, 1, 1, 1, 1); | |
| 489 | ||
| 490 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), 1, 3, 1, 1); | |
| 491 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), 1, 2, 1, 1); | |
| 492 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), 2, 1, 1, 1); | |
| 493 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), 3, 1, 1, 1); | |
| 494 | ||
| 495 | // Draw right upper corner | |
| 496 | G.FillRectangle(Brushes.Fuchsia, Width - 1, 0, 1, 1); | |
| 497 | G.FillRectangle(Brushes.Fuchsia, Width - 2, 0, 1, 1); | |
| 498 | G.FillRectangle(Brushes.Fuchsia, Width - 3, 0, 1, 1); | |
| 499 | G.FillRectangle(Brushes.Fuchsia, Width - 4, 0, 1, 1); | |
| 500 | G.FillRectangle(Brushes.Fuchsia, Width - 1, 1, 1, 1); | |
| 501 | G.FillRectangle(Brushes.Fuchsia, Width - 1, 2, 1, 1); | |
| 502 | G.FillRectangle(Brushes.Fuchsia, Width - 1, 3, 1, 1); | |
| 503 | G.FillRectangle(Brushes.Fuchsia, Width - 2, 1, 1, 1); | |
| 504 | ||
| 505 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), Width - 2, 3, 1, 1); | |
| 506 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), Width - 2, 2, 1, 1); | |
| 507 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), Width - 3, 1, 1, 1); | |
| 508 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), Width - 4, 1, 1, 1); | |
| 509 | ||
| 510 | // Draw Left bottom corner | |
| 511 | G.FillRectangle(Brushes.Fuchsia, 0, Height - 1, 1, 1); | |
| 512 | G.FillRectangle(Brushes.Fuchsia, 0, Height - 2, 1, 1); | |
| 513 | G.FillRectangle(Brushes.Fuchsia, 0, Height - 3, 1, 1); | |
| 514 | G.FillRectangle(Brushes.Fuchsia, 0, Height - 4, 1, 1); | |
| 515 | G.FillRectangle(Brushes.Fuchsia, 1, Height - 1, 1, 1); | |
| 516 | G.FillRectangle(Brushes.Fuchsia, 2, Height - 1, 1, 1); | |
| 517 | G.FillRectangle(Brushes.Fuchsia, 3, Height - 1, 1, 1); | |
| 518 | G.FillRectangle(Brushes.Fuchsia, 1, Height - 1, 1, 1); | |
| 519 | G.FillRectangle(Brushes.Fuchsia, 1, Height - 2, 1, 1); | |
| 520 | ||
| 521 | G.FillRectangle(new SolidBrush(Color.FromArgb(32, 41, 50)), 1, Height - 3, 1, 1); | |
| 522 | G.FillRectangle(new SolidBrush(Color.FromArgb(32, 41, 50)), 1, Height - 4, 1, 1); | |
| 523 | G.FillRectangle(new SolidBrush(Color.FromArgb(32, 41, 50)), 3, Height - 2, 1, 1); | |
| 524 | G.FillRectangle(new SolidBrush(Color.FromArgb(32, 41, 50)), 2, Height - 2, 1, 1); | |
| 525 | ||
| 526 | // Draw right bottom corner | |
| 527 | G.FillRectangle(Brushes.Fuchsia, Width - 1, Height, 1, 1); | |
| 528 | G.FillRectangle(Brushes.Fuchsia, Width - 2, Height, 1, 1); | |
| 529 | G.FillRectangle(Brushes.Fuchsia, Width - 3, Height, 1, 1); | |
| 530 | G.FillRectangle(Brushes.Fuchsia, Width - 4, Height, 1, 1); | |
| 531 | G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 1, 1, 1); | |
| 532 | G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 2, 1, 1); | |
| 533 | G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 3, 1, 1); | |
| 534 | G.FillRectangle(Brushes.Fuchsia, Width - 2, Height - 1, 1, 1); | |
| 535 | G.FillRectangle(Brushes.Fuchsia, Width - 3, Height - 1, 1, 1); | |
| 536 | G.FillRectangle(Brushes.Fuchsia, Width - 4, Height - 1, 1, 1); | |
| 537 | G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 4, 1, 1); | |
| 538 | G.FillRectangle(Brushes.Fuchsia, Width - 2, Height - 2, 1, 1); | |
| 539 | ||
| 540 | G.FillRectangle(new SolidBrush(Color.FromArgb(32, 41, 50)), Width - 2, Height - 3, 1, 1); | |
| 541 | G.FillRectangle(new SolidBrush(Color.FromArgb(32, 41, 50)), Width - 2, Height - 4, 1, 1); | |
| 542 | G.FillRectangle(new SolidBrush(Color.FromArgb(32, 41, 50)), Width - 4, Height - 2, 1, 1); | |
| 543 | G.FillRectangle(new SolidBrush(Color.FromArgb(32, 41, 50)), Width - 3, Height - 2, 1, 1); | |
| 544 | } | |
| 545 | ||
| 546 | G.DrawString(Text, new Font("Microsoft Sans Serif", 12, FontStyle.Bold), new SolidBrush(Color.FromArgb(255, 254, 255)), new Rectangle(20, 20, Width - 1, Height), new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near });
| |
| 547 | } | |
| 548 | } | |
| 549 | ||
| 550 | #endregion | |
| 551 | #region ControlBox | |
| 552 | ||
| 553 | class MonoFlat_ControlBox : Control | |
| 554 | {
| |
| 555 | ||
| 556 | #region Enums | |
| 557 | ||
| 558 | public enum ButtonHoverState | |
| 559 | {
| |
| 560 | Minimize, | |
| 561 | Maximize, | |
| 562 | Close, | |
| 563 | None | |
| 564 | } | |
| 565 | ||
| 566 | #endregion | |
| 567 | #region Variables | |
| 568 | ||
| 569 | private ButtonHoverState ButtonHState = ButtonHoverState.None; | |
| 570 | ||
| 571 | #endregion | |
| 572 | #region Properties | |
| 573 | ||
| 574 | private bool _EnableMaximize = true; | |
| 575 | public bool EnableMaximizeButton | |
| 576 | {
| |
| 577 | get { return _EnableMaximize; }
| |
| 578 | set | |
| 579 | {
| |
| 580 | _EnableMaximize = value; | |
| 581 | Invalidate(); | |
| 582 | } | |
| 583 | } | |
| 584 | ||
| 585 | private bool _EnableMinimize = true; | |
| 586 | public bool EnableMinimizeButton | |
| 587 | {
| |
| 588 | get { return _EnableMinimize; }
| |
| 589 | set | |
| 590 | {
| |
| 591 | _EnableMinimize = value; | |
| 592 | Invalidate(); | |
| 593 | } | |
| 594 | } | |
| 595 | ||
| 596 | private bool _EnableHoverHighlight = false; | |
| 597 | public bool EnableHoverHighlight | |
| 598 | {
| |
| 599 | get { return _EnableHoverHighlight; }
| |
| 600 | set | |
| 601 | {
| |
| 602 | _EnableHoverHighlight = value; | |
| 603 | Invalidate(); | |
| 604 | } | |
| 605 | } | |
| 606 | ||
| 607 | #endregion | |
| 608 | #region EventArgs | |
| 609 | ||
| 610 | protected override void OnResize(EventArgs e) | |
| 611 | {
| |
| 612 | base.OnResize(e); | |
| 613 | Size = new Size(100, 25); | |
| 614 | } | |
| 615 | ||
| 616 | protected override void OnMouseMove(MouseEventArgs e) | |
| 617 | {
| |
| 618 | base.OnMouseMove(e); | |
| 619 | int X = e.Location.X; | |
| 620 | int Y = e.Location.Y; | |
| 621 | if (Y > 0 && Y < (Height - 2)) | |
| 622 | {
| |
| 623 | if (X > 0 && X < 34) | |
| 624 | {
| |
| 625 | ButtonHState = ButtonHoverState.Minimize; | |
| 626 | } | |
| 627 | else if (X > 33 && X < 65) | |
| 628 | {
| |
| 629 | ButtonHState = ButtonHoverState.Maximize; | |
| 630 | } | |
| 631 | else if (X > 64 && X < Width) | |
| 632 | {
| |
| 633 | ButtonHState = ButtonHoverState.Close; | |
| 634 | } | |
| 635 | else | |
| 636 | {
| |
| 637 | ButtonHState = ButtonHoverState.None; | |
| 638 | } | |
| 639 | } | |
| 640 | else | |
| 641 | {
| |
| 642 | ButtonHState = ButtonHoverState.None; | |
| 643 | } | |
| 644 | Invalidate(); | |
| 645 | } | |
| 646 | ||
| 647 | protected override void OnMouseUp(MouseEventArgs e) | |
| 648 | {
| |
| 649 | base.OnMouseDown(e); | |
| 650 | switch (ButtonHState) | |
| 651 | {
| |
| 652 | case ButtonHoverState.Close: | |
| 653 | Parent.FindForm().Close(); | |
| 654 | break; | |
| 655 | case ButtonHoverState.Minimize: | |
| 656 | if (_EnableMinimize == true) | |
| 657 | {
| |
| 658 | Parent.FindForm().WindowState = FormWindowState.Minimized; | |
| 659 | } | |
| 660 | break; | |
| 661 | case ButtonHoverState.Maximize: | |
| 662 | if (_EnableMaximize == true) | |
| 663 | {
| |
| 664 | if (Parent.FindForm().WindowState == FormWindowState.Normal) | |
| 665 | {
| |
| 666 | Parent.FindForm().WindowState = FormWindowState.Maximized; | |
| 667 | } | |
| 668 | else | |
| 669 | {
| |
| 670 | Parent.FindForm().WindowState = FormWindowState.Normal; | |
| 671 | } | |
| 672 | } | |
| 673 | break; | |
| 674 | } | |
| 675 | } | |
| 676 | protected override void OnMouseLeave(EventArgs e) | |
| 677 | {
| |
| 678 | base.OnMouseLeave(e); | |
| 679 | ButtonHState = ButtonHoverState.None; | |
| 680 | Invalidate(); | |
| 681 | } | |
| 682 | ||
| 683 | protected override void OnMouseDown(MouseEventArgs e) | |
| 684 | {
| |
| 685 | base.OnMouseDown(e); | |
| 686 | Focus(); | |
| 687 | } | |
| 688 | ||
| 689 | #endregion | |
| 690 | ||
| 691 | public MonoFlat_ControlBox() | |
| 692 | : base() | |
| 693 | {
| |
| 694 | DoubleBuffered = true; | |
| 695 | Anchor = AnchorStyles.Top | AnchorStyles.Right; | |
| 696 | } | |
| 697 | ||
| 698 | protected override void OnCreateControl() | |
| 699 | {
| |
| 700 | base.OnCreateControl(); | |
| 701 | try | |
| 702 | {
| |
| 703 | Location = new Point(Parent.Width - 112, 15); | |
| 704 | } | |
| 705 | catch (Exception) | |
| 706 | {
| |
| 707 | } | |
| 708 | } | |
| 709 | ||
| 710 | protected override void OnPaint(PaintEventArgs e) | |
| 711 | {
| |
| 712 | base.OnPaint(e); | |
| 713 | Graphics G = e.Graphics; | |
| 714 | G.Clear(Color.FromArgb(181, 41, 42)); | |
| 715 | ||
| 716 | if (_EnableHoverHighlight == true) | |
| 717 | {
| |
| 718 | switch (ButtonHState) | |
| 719 | {
| |
| 720 | case ButtonHoverState.None: | |
| 721 | G.Clear(Color.FromArgb(181, 41, 42)); | |
| 722 | break; | |
| 723 | case ButtonHoverState.Minimize: | |
| 724 | if (_EnableMinimize == true) | |
| 725 | {
| |
| 726 | G.FillRectangle(new SolidBrush(Color.FromArgb(156, 35, 35)), new Rectangle(3, 0, 30, Height)); | |
| 727 | } | |
| 728 | break; | |
| 729 | case ButtonHoverState.Maximize: | |
| 730 | if (_EnableMaximize == true) | |
| 731 | {
| |
| 732 | G.FillRectangle(new SolidBrush(Color.FromArgb(156, 35, 35)), new Rectangle(35, 0, 30, Height)); | |
| 733 | } | |
| 734 | break; | |
| 735 | case ButtonHoverState.Close: | |
| 736 | G.FillRectangle(new SolidBrush(Color.FromArgb(156, 35, 35)), new Rectangle(66, 0, 35, Height)); | |
| 737 | break; | |
| 738 | } | |
| 739 | } | |
| 740 | ||
| 741 | //Close | |
| 742 | G.DrawString("r", new Font("Marlett", 12), new SolidBrush(Color.FromArgb(255, 254, 255)), new Point(Width - 16, 8), new StringFormat { Alignment = StringAlignment.Center });
| |
| 743 | ||
| 744 | //Maximize | |
| 745 | switch (Parent.FindForm().WindowState) | |
| 746 | {
| |
| 747 | case FormWindowState.Maximized: | |
| 748 | if (_EnableMaximize == true) | |
| 749 | {
| |
| 750 | G.DrawString("2", new Font("Marlett", 12), new SolidBrush(Color.FromArgb(255, 254, 255)), new Point(51, 7), new StringFormat { Alignment = StringAlignment.Center });
| |
| 751 | } | |
| 752 | else | |
| 753 | {
| |
| 754 | G.DrawString("2", new Font("Marlett", 12), new SolidBrush(Color.LightGray), new Point(51, 7), new StringFormat { Alignment = StringAlignment.Center });
| |
| 755 | } | |
| 756 | break; | |
| 757 | case FormWindowState.Normal: | |
| 758 | if (_EnableMaximize == true) | |
| 759 | {
| |
| 760 | G.DrawString("1", new Font("Marlett", 12), new SolidBrush(Color.FromArgb(255, 254, 255)), new Point(51, 7), new StringFormat { Alignment = StringAlignment.Center });
| |
| 761 | } | |
| 762 | else | |
| 763 | {
| |
| 764 | G.DrawString("1", new Font("Marlett", 12), new SolidBrush(Color.LightGray), new Point(51, 7), new StringFormat { Alignment = StringAlignment.Center });
| |
| 765 | } | |
| 766 | break; | |
| 767 | } | |
| 768 | ||
| 769 | //Minimize | |
| 770 | if (_EnableMinimize == true) | |
| 771 | {
| |
| 772 | G.DrawString("0", new Font("Marlett", 12), new SolidBrush(Color.FromArgb(255, 254, 255)), new Point(20, 7), new StringFormat { Alignment = StringAlignment.Center });
| |
| 773 | } | |
| 774 | else | |
| 775 | {
| |
| 776 | G.DrawString("0", new Font("Marlett", 12), new SolidBrush(Color.LightGray), new Point(20, 7), new StringFormat { Alignment = StringAlignment.Center });
| |
| 777 | } | |
| 778 | } | |
| 779 | } | |
| 780 | ||
| 781 | #endregion | |
| 782 | #region Button | |
| 783 | ||
| 784 | public class MonoFlat_Button : Control | |
| 785 | {
| |
| 786 | ||
| 787 | #region Variables | |
| 788 | ||
| 789 | private int MouseState; | |
| 790 | private GraphicsPath Shape; | |
| 791 | private LinearGradientBrush InactiveGB; | |
| 792 | private LinearGradientBrush PressedGB; | |
| 793 | private Rectangle R1; | |
| 794 | private Pen P1; | |
| 795 | private Pen P3; | |
| 796 | private Image _Image; | |
| 797 | private Size _ImageSize; | |
| 798 | private StringAlignment _TextAlignment = StringAlignment.Center; | |
| 799 | private Color _TextColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static. Assignment has been moved to the class constructors. | |
| 800 | private ContentAlignment _ImageAlign = ContentAlignment.MiddleLeft; | |
| 801 | ||
| 802 | #endregion | |
| 803 | #region Image Designer | |
| 804 | ||
| 805 | private static PointF ImageLocation(StringFormat SF, SizeF Area, SizeF ImageArea) | |
| 806 | {
| |
| 807 | PointF MyPoint = new PointF(); | |
| 808 | switch (SF.Alignment) | |
| 809 | {
| |
| 810 | case StringAlignment.Center: | |
| 811 | MyPoint.X = (float)((Area.Width - ImageArea.Width) / 2); | |
| 812 | break; | |
| 813 | case StringAlignment.Near: | |
| 814 | MyPoint.X = 2; | |
| 815 | break; | |
| 816 | case StringAlignment.Far: | |
| 817 | MyPoint.X = Area.Width - ImageArea.Width - 2; | |
| 818 | break; | |
| 819 | ||
| 820 | } | |
| 821 | ||
| 822 | switch (SF.LineAlignment) | |
| 823 | {
| |
| 824 | case StringAlignment.Center: | |
| 825 | MyPoint.Y = (float)((Area.Height - ImageArea.Height) / 2); | |
| 826 | break; | |
| 827 | case StringAlignment.Near: | |
| 828 | MyPoint.Y = 2; | |
| 829 | break; | |
| 830 | case StringAlignment.Far: | |
| 831 | MyPoint.Y = Area.Height - ImageArea.Height - 2; | |
| 832 | break; | |
| 833 | } | |
| 834 | return MyPoint; | |
| 835 | } | |
| 836 | ||
| 837 | private StringFormat GetStringFormat(ContentAlignment _ContentAlignment) | |
| 838 | {
| |
| 839 | StringFormat SF = new StringFormat(); | |
| 840 | switch (_ContentAlignment) | |
| 841 | {
| |
| 842 | case ContentAlignment.MiddleCenter: | |
| 843 | SF.LineAlignment = StringAlignment.Center; | |
| 844 | SF.Alignment = StringAlignment.Center; | |
| 845 | break; | |
| 846 | case ContentAlignment.MiddleLeft: | |
| 847 | SF.LineAlignment = StringAlignment.Center; | |
| 848 | SF.Alignment = StringAlignment.Near; | |
| 849 | break; | |
| 850 | case ContentAlignment.MiddleRight: | |
| 851 | SF.LineAlignment = StringAlignment.Center; | |
| 852 | SF.Alignment = StringAlignment.Far; | |
| 853 | break; | |
| 854 | case ContentAlignment.TopCenter: | |
| 855 | SF.LineAlignment = StringAlignment.Near; | |
| 856 | SF.Alignment = StringAlignment.Center; | |
| 857 | break; | |
| 858 | case ContentAlignment.TopLeft: | |
| 859 | SF.LineAlignment = StringAlignment.Near; | |
| 860 | SF.Alignment = StringAlignment.Near; | |
| 861 | break; | |
| 862 | case ContentAlignment.TopRight: | |
| 863 | SF.LineAlignment = StringAlignment.Near; | |
| 864 | SF.Alignment = StringAlignment.Far; | |
| 865 | break; | |
| 866 | case ContentAlignment.BottomCenter: | |
| 867 | SF.LineAlignment = StringAlignment.Far; | |
| 868 | SF.Alignment = StringAlignment.Center; | |
| 869 | break; | |
| 870 | case ContentAlignment.BottomLeft: | |
| 871 | SF.LineAlignment = StringAlignment.Far; | |
| 872 | SF.Alignment = StringAlignment.Near; | |
| 873 | break; | |
| 874 | case ContentAlignment.BottomRight: | |
| 875 | SF.LineAlignment = StringAlignment.Far; | |
| 876 | SF.Alignment = StringAlignment.Far; | |
| 877 | break; | |
| 878 | } | |
| 879 | return SF; | |
| 880 | } | |
| 881 | ||
| 882 | #endregion | |
| 883 | #region Properties | |
| 884 | ||
| 885 | public Image Image | |
| 886 | {
| |
| 887 | get | |
| 888 | {
| |
| 889 | return _Image; | |
| 890 | } | |
| 891 | set | |
| 892 | {
| |
| 893 | if (value == null) | |
| 894 | {
| |
| 895 | _ImageSize = Size.Empty; | |
| 896 | } | |
| 897 | else | |
| 898 | {
| |
| 899 | _ImageSize = value.Size; | |
| 900 | } | |
| 901 | ||
| 902 | _Image = value; | |
| 903 | Invalidate(); | |
| 904 | } | |
| 905 | } | |
| 906 | ||
| 907 | protected Size ImageSize | |
| 908 | {
| |
| 909 | get | |
| 910 | {
| |
| 911 | return _ImageSize; | |
| 912 | } | |
| 913 | } | |
| 914 | ||
| 915 | public ContentAlignment ImageAlign | |
| 916 | {
| |
| 917 | get | |
| 918 | {
| |
| 919 | return _ImageAlign; | |
| 920 | } | |
| 921 | set | |
| 922 | {
| |
| 923 | _ImageAlign = value; | |
| 924 | Invalidate(); | |
| 925 | } | |
| 926 | } | |
| 927 | ||
| 928 | public StringAlignment TextAlignment | |
| 929 | {
| |
| 930 | get | |
| 931 | {
| |
| 932 | return this._TextAlignment; | |
| 933 | } | |
| 934 | set | |
| 935 | {
| |
| 936 | this._TextAlignment = value; | |
| 937 | this.Invalidate(); | |
| 938 | } | |
| 939 | } | |
| 940 | ||
| 941 | public override Color ForeColor | |
| 942 | {
| |
| 943 | get | |
| 944 | {
| |
| 945 | return this._TextColor; | |
| 946 | } | |
| 947 | set | |
| 948 | {
| |
| 949 | this._TextColor = value; | |
| 950 | this.Invalidate(); | |
| 951 | } | |
| 952 | } | |
| 953 | ||
| 954 | #endregion | |
| 955 | #region EventArgs | |
| 956 | ||
| 957 | protected override void OnMouseUp(MouseEventArgs e) | |
| 958 | {
| |
| 959 | MouseState = 0; | |
| 960 | Invalidate(); | |
| 961 | base.OnMouseUp(e); | |
| 962 | } | |
| 963 | protected override void OnMouseDown(MouseEventArgs e) | |
| 964 | {
| |
| 965 | MouseState = 1; | |
| 966 | Focus(); | |
| 967 | Invalidate(); | |
| 968 | base.OnMouseDown(e); | |
| 969 | } | |
| 970 | ||
| 971 | protected override void OnMouseLeave(EventArgs e) | |
| 972 | {
| |
| 973 | MouseState = 0; | |
| 974 | Invalidate(); | |
| 975 | base.OnMouseLeave(e); | |
| 976 | } | |
| 977 | ||
| 978 | protected override void OnTextChanged(System.EventArgs e) | |
| 979 | {
| |
| 980 | Invalidate(); | |
| 981 | base.OnTextChanged(e); | |
| 982 | } | |
| 983 | ||
| 984 | #endregion | |
| 985 | ||
| 986 | public MonoFlat_Button() | |
| 987 | {
| |
| 988 | SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint), true); | |
| 989 | ||
| 990 | BackColor = Color.Transparent; | |
| 991 | DoubleBuffered = true; | |
| 992 | Font = new Font("Segoe UI", 12);
| |
| 993 | ForeColor = Color.FromArgb(255, 255, 255); | |
| 994 | Size = new Size(146, 41); | |
| 995 | _TextAlignment = StringAlignment.Center; | |
| 996 | P1 = new Pen(Color.FromArgb(181, 41, 42)); // P1 = Border color | |
| 997 | P3 = new Pen(Color.FromArgb(165, 37, 37)); // P3 = Border color when pressed | |
| 998 | } | |
| 999 | ||
| 1000 | protected override void OnResize(System.EventArgs e) | |
| 1001 | {
| |
| 1002 | base.OnResize(e); | |
| 1003 | if (Width > 0 && Height > 0) | |
| 1004 | {
| |
| 1005 | ||
| 1006 | Shape = new GraphicsPath(); | |
| 1007 | R1 = new Rectangle(0, 0, Width, Height); | |
| 1008 | ||
| 1009 | InactiveGB = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), Color.FromArgb(181, 41, 42), Color.FromArgb(181, 41, 42), 90.0F); | |
| 1010 | PressedGB = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), Color.FromArgb(165, 37, 37), Color.FromArgb(165, 37, 37), 90.0F); | |
| 1011 | } | |
| 1012 | ||
| 1013 | Shape.AddArc(0, 0, 10, 10, 180, 90); | |
| 1014 | Shape.AddArc(Width - 11, 0, 10, 10, -90, 90); | |
| 1015 | Shape.AddArc(Width - 11, Height - 11, 10, 10, 0, 90); | |
| 1016 | Shape.AddArc(0, Height - 11, 10, 10, 90, 90); | |
| 1017 | Shape.CloseAllFigures(); | |
| 1018 | Invalidate(); | |
| 1019 | } | |
| 1020 | ||
| 1021 | protected override void OnPaint(PaintEventArgs e) | |
| 1022 | {
| |
| 1023 | var G = e.Graphics; | |
| 1024 | G.SmoothingMode = SmoothingMode.HighQuality; | |
| 1025 | PointF ipt = ImageLocation(GetStringFormat(ImageAlign), Size, ImageSize); | |
| 1026 | ||
| 1027 | switch (MouseState) | |
| 1028 | {
| |
| 1029 | case 0: | |
| 1030 | //Inactive | |
| 1031 | G.FillPath(InactiveGB, Shape); | |
| 1032 | // Fill button body with InactiveGB color gradient | |
| 1033 | G.DrawPath(P1, Shape); | |
| 1034 | // Draw button border [InactiveGB] | |
| 1035 | if ((Image == null)) | |
| 1036 | {
| |
| 1037 | G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat | |
| 1038 | {
| |
| 1039 | Alignment = _TextAlignment, | |
| 1040 | LineAlignment = StringAlignment.Center | |
| 1041 | }); | |
| 1042 | } | |
| 1043 | else | |
| 1044 | {
| |
| 1045 | G.DrawImage(_Image, ipt.X, ipt.Y, ImageSize.Width, ImageSize.Height); | |
| 1046 | G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat | |
| 1047 | {
| |
| 1048 | Alignment = _TextAlignment, | |
| 1049 | LineAlignment = StringAlignment.Center | |
| 1050 | }); | |
| 1051 | } | |
| 1052 | break; | |
| 1053 | case 1: | |
| 1054 | //Pressed | |
| 1055 | G.FillPath(PressedGB, Shape); | |
| 1056 | // Fill button body with PressedGB color gradient | |
| 1057 | G.DrawPath(P3, Shape); | |
| 1058 | // Draw button border [PressedGB] | |
| 1059 | ||
| 1060 | if ((Image == null)) | |
| 1061 | {
| |
| 1062 | G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat | |
| 1063 | {
| |
| 1064 | Alignment = _TextAlignment, | |
| 1065 | LineAlignment = StringAlignment.Center | |
| 1066 | }); | |
| 1067 | } | |
| 1068 | else | |
| 1069 | {
| |
| 1070 | G.DrawImage(_Image, ipt.X, ipt.Y, ImageSize.Width, ImageSize.Height); | |
| 1071 | G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat | |
| 1072 | {
| |
| 1073 | Alignment = _TextAlignment, | |
| 1074 | LineAlignment = StringAlignment.Center | |
| 1075 | }); | |
| 1076 | } | |
| 1077 | break; | |
| 1078 | } | |
| 1079 | base.OnPaint(e); | |
| 1080 | } | |
| 1081 | } | |
| 1082 | ||
| 1083 | #endregion | |
| 1084 | #region Social Button | |
| 1085 | ||
| 1086 | public class MonoFlat_SocialButton : Control | |
| 1087 | {
| |
| 1088 | ||
| 1089 | #region Variables | |
| 1090 | ||
| 1091 | private Image _Image; | |
| 1092 | private Size _ImageSize; | |
| 1093 | private Color EllipseColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static. Assignment has been moved to the class constructors. | |
| 1094 | ||
| 1095 | #endregion | |
| 1096 | #region Properties | |
| 1097 | ||
| 1098 | public Image Image | |
| 1099 | {
| |
| 1100 | get | |
| 1101 | {
| |
| 1102 | return _Image; | |
| 1103 | } | |
| 1104 | set | |
| 1105 | {
| |
| 1106 | if (value == null) | |
| 1107 | {
| |
| 1108 | _ImageSize = Size.Empty; | |
| 1109 | } | |
| 1110 | else | |
| 1111 | {
| |
| 1112 | _ImageSize = value.Size; | |
| 1113 | } | |
| 1114 | ||
| 1115 | _Image = value; | |
| 1116 | Invalidate(); | |
| 1117 | } | |
| 1118 | } | |
| 1119 | ||
| 1120 | protected Size ImageSize | |
| 1121 | {
| |
| 1122 | get | |
| 1123 | {
| |
| 1124 | return _ImageSize; | |
| 1125 | } | |
| 1126 | } | |
| 1127 | ||
| 1128 | #endregion | |
| 1129 | #region EventArgs | |
| 1130 | ||
| 1131 | protected override void OnResize(EventArgs e) | |
| 1132 | {
| |
| 1133 | base.OnResize(e); | |
| 1134 | this.Size = new Size(54, 54); | |
| 1135 | } | |
| 1136 | ||
| 1137 | protected override void OnMouseEnter(EventArgs e) | |
| 1138 | {
| |
| 1139 | base.OnMouseEnter(e); | |
| 1140 | EllipseColor = Color.FromArgb(181, 41, 42); | |
| 1141 | Refresh(); | |
| 1142 | } | |
| 1143 | protected override void OnMouseLeave(EventArgs e) | |
| 1144 | {
| |
| 1145 | base.OnMouseLeave(e); | |
| 1146 | EllipseColor = Color.FromArgb(66, 76, 85); | |
| 1147 | Refresh(); | |
| 1148 | } | |
| 1149 | ||
| 1150 | protected override void OnMouseDown(MouseEventArgs e) | |
| 1151 | {
| |
| 1152 | base.OnMouseDown(e); | |
| 1153 | EllipseColor = Color.FromArgb(153, 34, 34); | |
| 1154 | Focus(); | |
| 1155 | Refresh(); | |
| 1156 | } | |
| 1157 | protected override void OnMouseUp(MouseEventArgs e) | |
| 1158 | {
| |
| 1159 | base.OnMouseUp(e); | |
| 1160 | EllipseColor = Color.FromArgb(181, 41, 42); | |
| 1161 | Refresh(); | |
| 1162 | } | |
| 1163 | ||
| 1164 | #endregion | |
| 1165 | #region Image Designer | |
| 1166 | ||
| 1167 | private static PointF ImageLocation(StringFormat SF, SizeF Area, SizeF ImageArea) | |
| 1168 | {
| |
| 1169 | PointF MyPoint = new PointF(); | |
| 1170 | switch (SF.Alignment) | |
| 1171 | {
| |
| 1172 | case StringAlignment.Center: | |
| 1173 | MyPoint.X = (float)((Area.Width - ImageArea.Width) / 2); | |
| 1174 | break; | |
| 1175 | } | |
| 1176 | ||
| 1177 | switch (SF.LineAlignment) | |
| 1178 | {
| |
| 1179 | case StringAlignment.Center: | |
| 1180 | MyPoint.Y = (float)((Area.Height - ImageArea.Height) / 2); | |
| 1181 | break; | |
| 1182 | } | |
| 1183 | return MyPoint; | |
| 1184 | } | |
| 1185 | ||
| 1186 | private StringFormat GetStringFormat(ContentAlignment _ContentAlignment) | |
| 1187 | {
| |
| 1188 | StringFormat SF = new StringFormat(); | |
| 1189 | switch (_ContentAlignment) | |
| 1190 | {
| |
| 1191 | case ContentAlignment.MiddleCenter: | |
| 1192 | SF.LineAlignment = StringAlignment.Center; | |
| 1193 | SF.Alignment = StringAlignment.Center; | |
| 1194 | break; | |
| 1195 | } | |
| 1196 | return SF; | |
| 1197 | } | |
| 1198 | ||
| 1199 | #endregion | |
| 1200 | ||
| 1201 | public MonoFlat_SocialButton() | |
| 1202 | {
| |
| 1203 | DoubleBuffered = true; | |
| 1204 | EllipseColor = Color.FromArgb(66, 76, 85); | |
| 1205 | } | |
| 1206 | ||
| 1207 | protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) | |
| 1208 | {
| |
| 1209 | Graphics G = e.Graphics; | |
| 1210 | G.Clear(Parent.BackColor); | |
| 1211 | G.SmoothingMode = SmoothingMode.HighQuality; | |
| 1212 | ||
| 1213 | PointF ImgPoint = ImageLocation(GetStringFormat(ContentAlignment.MiddleCenter), Size, ImageSize); | |
| 1214 | G.FillEllipse(new SolidBrush(EllipseColor), new Rectangle(0, 0, 53, 53)); | |
| 1215 | ||
| 1216 | // HINTS: | |
| 1217 | // The best size for the drawn image is 32x32\ | |
| 1218 | // The best matching color of drawn image is (RGB: 31, 40, 49) | |
| 1219 | if (Image != null) | |
| 1220 | {
| |
| 1221 | G.DrawImage(_Image, (int)ImgPoint.X, (int)ImgPoint.Y, ImageSize.Width, ImageSize.Height); | |
| 1222 | } | |
| 1223 | } | |
| 1224 | } | |
| 1225 | ||
| 1226 | #endregion | |
| 1227 | #region Label | |
| 1228 | ||
| 1229 | public class MonoFlat_Label : Label | |
| 1230 | {
| |
| 1231 | ||
| 1232 | public MonoFlat_Label() | |
| 1233 | {
| |
| 1234 | Font = new Font("Segoe UI", 9);
| |
| 1235 | ForeColor = Color.FromArgb(116, 125, 132); | |
| 1236 | BackColor = Color.Transparent; | |
| 1237 | } | |
| 1238 | } | |
| 1239 | ||
| 1240 | #endregion | |
| 1241 | #region Link Label | |
| 1242 | public class MonoFlat_LinkLabel : LinkLabel | |
| 1243 | {
| |
| 1244 | ||
| 1245 | public MonoFlat_LinkLabel() | |
| 1246 | {
| |
| 1247 | Font = new Font("Segoe UI", 9, FontStyle.Regular);
| |
| 1248 | BackColor = Color.Transparent; | |
| 1249 | LinkColor = Color.FromArgb(181, 41, 42); | |
| 1250 | ActiveLinkColor = Color.FromArgb(153, 34, 34); | |
| 1251 | VisitedLinkColor = Color.FromArgb(181, 41, 42); | |
| 1252 | LinkBehavior = LinkBehavior.NeverUnderline; | |
| 1253 | } | |
| 1254 | } | |
| 1255 | ||
| 1256 | #endregion | |
| 1257 | #region Header Label | |
| 1258 | ||
| 1259 | public class MonoFlat_HeaderLabel : Label | |
| 1260 | {
| |
| 1261 | ||
| 1262 | public MonoFlat_HeaderLabel() | |
| 1263 | {
| |
| 1264 | Font = new Font("Segoe UI", 11, FontStyle.Bold);
| |
| 1265 | ForeColor = Color.FromArgb(255, 255, 255); | |
| 1266 | BackColor = Color.Transparent; | |
| 1267 | } | |
| 1268 | } | |
| 1269 | ||
| 1270 | #endregion | |
| 1271 | #region Toggle Button | |
| 1272 | ||
| 1273 | [DefaultEvent("ToggledChanged")]
| |
| 1274 | public class MonoFlat_Toggle : Control | |
| 1275 | {
| |
| 1276 | ||
| 1277 | #region Enums | |
| 1278 | ||
| 1279 | public enum _Type | |
| 1280 | {
| |
| 1281 | CheckMark, | |
| 1282 | OnOff, | |
| 1283 | YesNo, | |
| 1284 | IO | |
| 1285 | } | |
| 1286 | ||
| 1287 | #endregion | |
| 1288 | #region Variables | |
| 1289 | ||
| 1290 | public delegate void ToggledChangedEventHandler(); | |
| 1291 | private ToggledChangedEventHandler ToggledChangedEvent; | |
| 1292 | ||
| 1293 | public event ToggledChangedEventHandler ToggledChanged | |
| 1294 | {
| |
| 1295 | add | |
| 1296 | {
| |
| 1297 | ToggledChangedEvent = (ToggledChangedEventHandler)System.Delegate.Combine(ToggledChangedEvent, value); | |
| 1298 | } | |
| 1299 | remove | |
| 1300 | {
| |
| 1301 | ToggledChangedEvent = (ToggledChangedEventHandler)System.Delegate.Remove(ToggledChangedEvent, value); | |
| 1302 | } | |
| 1303 | } | |
| 1304 | ||
| 1305 | private bool _Toggled; | |
| 1306 | private _Type ToggleType; | |
| 1307 | private Rectangle Bar; | |
| 1308 | private int _Width; | |
| 1309 | private int _Height; | |
| 1310 | ||
| 1311 | #endregion | |
| 1312 | #region Properties | |
| 1313 | ||
| 1314 | public bool Toggled | |
| 1315 | {
| |
| 1316 | get | |
| 1317 | {
| |
| 1318 | return _Toggled; | |
| 1319 | } | |
| 1320 | set | |
| 1321 | {
| |
| 1322 | _Toggled = value; | |
| 1323 | Invalidate(); | |
| 1324 | if (ToggledChangedEvent != null) | |
| 1325 | ToggledChangedEvent(); | |
| 1326 | } | |
| 1327 | } | |
| 1328 | ||
| 1329 | public _Type Type | |
| 1330 | {
| |
| 1331 | get | |
| 1332 | {
| |
| 1333 | return ToggleType; | |
| 1334 | } | |
| 1335 | set | |
| 1336 | {
| |
| 1337 | ToggleType = value; | |
| 1338 | Invalidate(); | |
| 1339 | } | |
| 1340 | } | |
| 1341 | ||
| 1342 | #endregion | |
| 1343 | #region EventArgs | |
| 1344 | ||
| 1345 | protected override void OnResize(EventArgs e) | |
| 1346 | {
| |
| 1347 | base.OnResize(e); | |
| 1348 | this.Size = new Size(76, 33); | |
| 1349 | } | |
| 1350 | ||
| 1351 | protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) | |
| 1352 | {
| |
| 1353 | base.OnMouseUp(e); | |
| 1354 | Toggled = !Toggled; | |
| 1355 | Focus(); | |
| 1356 | } | |
| 1357 | ||
| 1358 | #endregion | |
| 1359 | ||
| 1360 | public MonoFlat_Toggle() | |
| 1361 | {
| |
| 1362 | SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint), true); | |
| 1363 | } | |
| 1364 | ||
| 1365 | protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) | |
| 1366 | {
| |
| 1367 | base.OnPaint(e); | |
| 1368 | System.Drawing.Graphics G = e.Graphics; | |
| 1369 | ||
| 1370 | G.SmoothingMode = SmoothingMode.HighQuality; | |
| 1371 | G.Clear(Parent.BackColor); | |
| 1372 | _Width = Width - 1; | |
| 1373 | _Height = Height - 1; | |
| 1374 | ||
| 1375 | GraphicsPath GP = default(GraphicsPath); | |
| 1376 | GraphicsPath GP2 = new GraphicsPath(); | |
| 1377 | Rectangle BaseRect = new Rectangle(0, 0, _Width, _Height); | |
| 1378 | Rectangle ThumbRect = new Rectangle(_Width / 2, 0, 38, _Height); | |
| 1379 | ||
| 1380 | G.SmoothingMode = (System.Drawing.Drawing2D.SmoothingMode)2; | |
| 1381 | G.PixelOffsetMode = (System.Drawing.Drawing2D.PixelOffsetMode)2; | |
| 1382 | G.TextRenderingHint = (System.Drawing.Text.TextRenderingHint)5; | |
| 1383 | G.Clear(BackColor); | |
| 1384 | ||
| 1385 | GP = RoundRectangle.RoundRect(BaseRect, 4); | |
| 1386 | ThumbRect = new Rectangle(4, 4, 36, _Height - 8); | |
| 1387 | GP2 = RoundRectangle.RoundRect(ThumbRect, 4); | |
| 1388 | G.FillPath(new SolidBrush(Color.FromArgb(66, 76, 85)), GP); | |
| 1389 | G.FillPath(new SolidBrush(Color.FromArgb(32, 41, 50)), GP2); | |
| 1390 | ||
| 1391 | if (_Toggled) | |
| 1392 | {
| |
| 1393 | GP = RoundRectangle.RoundRect(BaseRect, 4); | |
| 1394 | ThumbRect = new Rectangle((_Width / 2) - 2, 4, 36, _Height - 8); | |
| 1395 | GP2 = RoundRectangle.RoundRect(ThumbRect, 4); | |
| 1396 | G.FillPath(new SolidBrush(Color.FromArgb(181, 41, 42)), GP); | |
| 1397 | G.FillPath(new SolidBrush(Color.FromArgb(32, 41, 50)), GP2); | |
| 1398 | } | |
| 1399 | ||
| 1400 | // Draw string | |
| 1401 | switch (ToggleType) | |
| 1402 | {
| |
| 1403 | case _Type.CheckMark: | |
| 1404 | if (Toggled) | |
| 1405 | {
| |
| 1406 | G.DrawString("ü", new Font("Wingdings", 18, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 19, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
| |
| 1407 | } | |
| 1408 | else | |
| 1409 | {
| |
| 1410 | G.DrawString("r", new Font("Marlett", 14, FontStyle.Regular), Brushes.DimGray, Bar.X + 59, Bar.Y + 18, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
| |
| 1411 | } | |
| 1412 | break; | |
| 1413 | case _Type.OnOff: | |
| 1414 | if (Toggled) | |
| 1415 | {
| |
| 1416 | G.DrawString("ON", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 16, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
| |
| 1417 | } | |
| 1418 | else | |
| 1419 | {
| |
| 1420 | G.DrawString("OFF", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 57, Bar.Y + 16, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
| |
| 1421 | } | |
| 1422 | break; | |
| 1423 | case _Type.YesNo: | |
| 1424 | if (Toggled) | |
| 1425 | {
| |
| 1426 | G.DrawString("YES", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 19, Bar.Y + 16, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
| |
| 1427 | } | |
| 1428 | else | |
| 1429 | {
| |
| 1430 | G.DrawString("NO", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 56, Bar.Y + 16, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
| |
| 1431 | } | |
| 1432 | break; | |
| 1433 | case _Type.IO: | |
| 1434 | if (Toggled) | |
| 1435 | {
| |
| 1436 | G.DrawString("I", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 16, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
| |
| 1437 | } | |
| 1438 | else | |
| 1439 | {
| |
| 1440 | G.DrawString("O", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 57, Bar.Y + 16, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
| |
| 1441 | } | |
| 1442 | break; | |
| 1443 | } | |
| 1444 | } | |
| 1445 | } | |
| 1446 | ||
| 1447 | #endregion | |
| 1448 | #region CheckBox | |
| 1449 | ||
| 1450 | [DefaultEvent("CheckedChanged")]
| |
| 1451 | public class MonoFlat_CheckBox : Control | |
| 1452 | {
| |
| 1453 | ||
| 1454 | #region Variables | |
| 1455 | ||
| 1456 | private int X; | |
| 1457 | private bool _Checked = false; | |
| 1458 | private GraphicsPath Shape; | |
| 1459 | ||
| 1460 | #endregion | |
| 1461 | #region Properties | |
| 1462 | ||
| 1463 | public bool Checked | |
| 1464 | {
| |
| 1465 | get | |
| 1466 | {
| |
| 1467 | return _Checked; | |
| 1468 | } | |
| 1469 | set | |
| 1470 | {
| |
| 1471 | _Checked = value; | |
| 1472 | Invalidate(); | |
| 1473 | } | |
| 1474 | } | |
| 1475 | ||
| 1476 | #endregion | |
| 1477 | #region EventArgs | |
| 1478 | ||
| 1479 | public delegate void CheckedChangedEventHandler(object sender); | |
| 1480 | private CheckedChangedEventHandler CheckedChangedEvent; | |
| 1481 | ||
| 1482 | public event CheckedChangedEventHandler CheckedChanged | |
| 1483 | {
| |
| 1484 | add | |
| 1485 | {
| |
| 1486 | CheckedChangedEvent = (CheckedChangedEventHandler)System.Delegate.Combine(CheckedChangedEvent, value); | |
| 1487 | } | |
| 1488 | remove | |
| 1489 | {
| |
| 1490 | CheckedChangedEvent = (CheckedChangedEventHandler)System.Delegate.Remove(CheckedChangedEvent, value); | |
| 1491 | } | |
| 1492 | } | |
| 1493 | ||
| 1494 | ||
| 1495 | protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) | |
| 1496 | {
| |
| 1497 | base.OnMouseMove(e); | |
| 1498 | X = e.Location.X; | |
| 1499 | Invalidate(); | |
| 1500 | } | |
| 1501 | protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) | |
| 1502 | {
| |
| 1503 | _Checked = !_Checked; | |
| 1504 | Focus(); | |
| 1505 | if (CheckedChangedEvent != null) | |
| 1506 | CheckedChangedEvent(this); | |
| 1507 | base.OnMouseDown(e); | |
| 1508 | } | |
| 1509 | ||
| 1510 | protected override void OnResize(EventArgs e) | |
| 1511 | {
| |
| 1512 | base.OnResize(e); | |
| 1513 | ||
| 1514 | this.Height = 16; | |
| 1515 | ||
| 1516 | Shape = new GraphicsPath(); | |
| 1517 | Shape.AddArc(0, 0, 10, 10, 180, 90); | |
| 1518 | Shape.AddArc(Width - 11, 0, 10, 10, -90, 90); | |
| 1519 | Shape.AddArc(Width - 11, Height - 11, 10, 10, 0, 90); | |
| 1520 | Shape.AddArc(0, Height - 11, 10, 10, 90, 90); | |
| 1521 | Shape.CloseAllFigures(); | |
| 1522 | Invalidate(); | |
| 1523 | } | |
| 1524 | ||
| 1525 | #endregion | |
| 1526 | ||
| 1527 | public MonoFlat_CheckBox() | |
| 1528 | {
| |
| 1529 | Width = 148; | |
| 1530 | Height = 16; | |
| 1531 | Font = new Font("Microsoft Sans Serif", 9);
| |
| 1532 | DoubleBuffered = true; | |
| 1533 | } | |
| 1534 | ||
| 1535 | protected override void OnPaint(PaintEventArgs e) | |
| 1536 | {
| |
| 1537 | base.OnPaint(e); | |
| 1538 | Graphics G = e.Graphics; | |
| 1539 | G.Clear(Parent.BackColor); | |
| 1540 | ||
| 1541 | if (_Checked) | |
| 1542 | {
| |
| 1543 | G.FillRectangle(new SolidBrush(Color.FromArgb(66, 76, 85)), new Rectangle(0, 0, 16, 16)); | |
| 1544 | G.FillRectangle(new SolidBrush(Color.FromArgb(66, 76, 85)), new Rectangle(1, 1, 16 - 2, 16 - 2)); | |
| 1545 | } | |
| 1546 | else | |
| 1547 | {
| |
| 1548 | G.FillRectangle(new SolidBrush(Color.FromArgb(66, 76, 85)), new Rectangle(0, 0, 16, 16)); | |
| 1549 | G.FillRectangle(new SolidBrush(Color.FromArgb(66, 76, 85)), new Rectangle(1, 1, 16 - 2, 16 - 2)); | |
| 1550 | } | |
| 1551 | ||
| 1552 | if (Enabled == true) | |
| 1553 | {
| |
| 1554 | if (_Checked) | |
| 1555 | {
| |
| 1556 | G.DrawString("a", new Font("Marlett", 16), new SolidBrush(Color.FromArgb(181, 41, 42)), new Point(-5, -3));
| |
| 1557 | } | |
| 1558 | } | |
| 1559 | else | |
| 1560 | {
| |
| 1561 | if (_Checked) | |
| 1562 | {
| |
| 1563 | G.DrawString("a", new Font("Marlett", 16), new SolidBrush(Color.Gray), new Point(-5, -3));
| |
| 1564 | } | |
| 1565 | } | |
| 1566 | ||
| 1567 | G.DrawString(Text, Font, new SolidBrush(Color.FromArgb(116, 125, 132)), new Point(20, 0)); | |
| 1568 | } | |
| 1569 | } | |
| 1570 | #endregion | |
| 1571 | #region Radio Button | |
| 1572 | ||
| 1573 | [DefaultEvent("CheckedChanged")]
| |
| 1574 | public class MonoFlat_RadioButton : Control | |
| 1575 | {
| |
| 1576 | ||
| 1577 | #region Variables | |
| 1578 | ||
| 1579 | private int X; | |
| 1580 | private bool _Checked; | |
| 1581 | ||
| 1582 | #endregion | |
| 1583 | #region Properties | |
| 1584 | ||
| 1585 | public bool Checked | |
| 1586 | {
| |
| 1587 | get | |
| 1588 | {
| |
| 1589 | return _Checked; | |
| 1590 | } | |
| 1591 | set | |
| 1592 | {
| |
| 1593 | _Checked = value; | |
| 1594 | InvalidateControls(); | |
| 1595 | if (CheckedChangedEvent != null) | |
| 1596 | CheckedChangedEvent(this); | |
| 1597 | Invalidate(); | |
| 1598 | } | |
| 1599 | } | |
| 1600 | ||
| 1601 | #endregion | |
| 1602 | #region EventArgs | |
| 1603 | ||
| 1604 | public delegate void CheckedChangedEventHandler(object sender); | |
| 1605 | private CheckedChangedEventHandler CheckedChangedEvent; | |
| 1606 | ||
| 1607 | public event CheckedChangedEventHandler CheckedChanged | |
| 1608 | {
| |
| 1609 | add | |
| 1610 | {
| |
| 1611 | CheckedChangedEvent = (CheckedChangedEventHandler)System.Delegate.Combine(CheckedChangedEvent, value); | |
| 1612 | } | |
| 1613 | remove | |
| 1614 | {
| |
| 1615 | CheckedChangedEvent = (CheckedChangedEventHandler)System.Delegate.Remove(CheckedChangedEvent, value); | |
| 1616 | } | |
| 1617 | } | |
| 1618 | ||
| 1619 | ||
| 1620 | protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) | |
| 1621 | {
| |
| 1622 | if (!_Checked) | |
| 1623 | {
| |
| 1624 | @Checked = true; | |
| 1625 | } | |
| 1626 | Focus(); | |
| 1627 | base.OnMouseDown(e); | |
| 1628 | } | |
| 1629 | protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) | |
| 1630 | {
| |
| 1631 | base.OnMouseMove(e); | |
| 1632 | X = e.X; | |
| 1633 | Invalidate(); | |
| 1634 | } | |
| 1635 | protected override void OnTextChanged(System.EventArgs e) | |
| 1636 | {
| |
| 1637 | base.OnTextChanged(e); | |
| 1638 | int textSize = 0; | |
| 1639 | textSize = (int)(this.CreateGraphics().MeasureString(Text, Font).Width); | |
| 1640 | this.Width = 28 + textSize; | |
| 1641 | } | |
| 1642 | ||
| 1643 | protected override void OnResize(EventArgs e) | |
| 1644 | {
| |
| 1645 | base.OnResize(e); | |
| 1646 | this.Height = 17; | |
| 1647 | } | |
| 1648 | ||
| 1649 | #endregion | |
| 1650 | ||
| 1651 | public MonoFlat_RadioButton() | |
| 1652 | {
| |
| 1653 | Width = 159; | |
| 1654 | Height = 17; | |
| 1655 | DoubleBuffered = true; | |
| 1656 | } | |
| 1657 | ||
| 1658 | private void InvalidateControls() | |
| 1659 | {
| |
| 1660 | if (!IsHandleCreated || !_Checked) | |
| 1661 | {
| |
| 1662 | return; | |
| 1663 | } | |
| 1664 | ||
| 1665 | foreach (Control _Control in Parent.Controls) | |
| 1666 | {
| |
| 1667 | if (_Control != this && _Control is MonoFlat_RadioButton) | |
| 1668 | {
| |
| 1669 | ((MonoFlat_RadioButton)_Control).Checked = false; | |
| 1670 | } | |
| 1671 | } | |
| 1672 | } | |
| 1673 | ||
| 1674 | protected override void OnPaint(PaintEventArgs e) | |
| 1675 | {
| |
| 1676 | base.OnPaint(e); | |
| 1677 | Graphics G = e.Graphics; | |
| 1678 | G.Clear(Parent.BackColor); | |
| 1679 | G.SmoothingMode = SmoothingMode.HighQuality; | |
| 1680 | ||
| 1681 | G.FillEllipse(new SolidBrush(Color.FromArgb(66, 76, 85)), new Rectangle(0, 0, 16, 16)); | |
| 1682 | ||
| 1683 | if (_Checked) | |
| 1684 | {
| |
| 1685 | G.DrawString("a", new Font("Marlett", 15), new SolidBrush(Color.FromArgb(181, 41, 42)), new Point(-3, -2));
| |
| 1686 | } | |
| 1687 | ||
| 1688 | G.DrawString(Text, Font, new SolidBrush(Color.FromArgb(116, 125, 132)), new Point(20, 0)); | |
| 1689 | } | |
| 1690 | } | |
| 1691 | ||
| 1692 | #endregion | |
| 1693 | #region TextBox | |
| 1694 | ||
| 1695 | [DefaultEvent("TextChanged")]
| |
| 1696 | public class MonoFlat_TextBox : Control | |
| 1697 | {
| |
| 1698 | ||
| 1699 | #region Variables | |
| 1700 | ||
| 1701 | public TextBox MonoFlatTB = new TextBox(); | |
| 1702 | private int _maxchars = 32767; | |
| 1703 | private bool _ReadOnly; | |
| 1704 | private bool _Multiline; | |
| 1705 | private Image _Image; | |
| 1706 | private Size _ImageSize; | |
| 1707 | private HorizontalAlignment ALNType; | |
| 1708 | private bool isPasswordMasked = false; | |
| 1709 | private Pen P1; | |
| 1710 | private SolidBrush B1; | |
| 1711 | private GraphicsPath Shape; | |
| 1712 | ||
| 1713 | #endregion | |
| 1714 | #region Properties | |
| 1715 | ||
| 1716 | public HorizontalAlignment TextAlignment | |
| 1717 | {
| |
| 1718 | get | |
| 1719 | {
| |
| 1720 | return ALNType; | |
| 1721 | } | |
| 1722 | set | |
| 1723 | {
| |
| 1724 | ALNType = value; | |
| 1725 | Invalidate(); | |
| 1726 | } | |
| 1727 | } | |
| 1728 | public int MaxLength | |
| 1729 | {
| |
| 1730 | get | |
| 1731 | {
| |
| 1732 | return _maxchars; | |
| 1733 | } | |
| 1734 | set | |
| 1735 | {
| |
| 1736 | _maxchars = value; | |
| 1737 | MonoFlatTB.MaxLength = MaxLength; | |
| 1738 | Invalidate(); | |
| 1739 | } | |
| 1740 | } | |
| 1741 | ||
| 1742 | public bool UseSystemPasswordChar | |
| 1743 | {
| |
| 1744 | get | |
| 1745 | {
| |
| 1746 | return isPasswordMasked; | |
| 1747 | } | |
| 1748 | set | |
| 1749 | {
| |
| 1750 | MonoFlatTB.UseSystemPasswordChar = UseSystemPasswordChar; | |
| 1751 | isPasswordMasked = value; | |
| 1752 | Invalidate(); | |
| 1753 | } | |
| 1754 | } | |
| 1755 | public bool ReadOnly | |
| 1756 | {
| |
| 1757 | get | |
| 1758 | {
| |
| 1759 | return _ReadOnly; | |
| 1760 | } | |
| 1761 | set | |
| 1762 | {
| |
| 1763 | _ReadOnly = value; | |
| 1764 | if (MonoFlatTB != null) | |
| 1765 | {
| |
| 1766 | MonoFlatTB.ReadOnly = value; | |
| 1767 | } | |
| 1768 | } | |
| 1769 | } | |
| 1770 | public bool Multiline | |
| 1771 | {
| |
| 1772 | get | |
| 1773 | {
| |
| 1774 | return _Multiline; | |
| 1775 | } | |
| 1776 | set | |
| 1777 | {
| |
| 1778 | _Multiline = value; | |
| 1779 | if (MonoFlatTB != null) | |
| 1780 | {
| |
| 1781 | MonoFlatTB.Multiline = value; | |
| 1782 | ||
| 1783 | if (value) | |
| 1784 | {
| |
| 1785 | MonoFlatTB.Height = Height - 23; | |
| 1786 | } | |
| 1787 | else | |
| 1788 | {
| |
| 1789 | Height = MonoFlatTB.Height + 23; | |
| 1790 | } | |
| 1791 | } | |
| 1792 | } | |
| 1793 | } | |
| 1794 | ||
| 1795 | public Image Image | |
| 1796 | {
| |
| 1797 | get | |
| 1798 | {
| |
| 1799 | return _Image; | |
| 1800 | } | |
| 1801 | set | |
| 1802 | {
| |
| 1803 | if (value == null) | |
| 1804 | {
| |
| 1805 | _ImageSize = Size.Empty; | |
| 1806 | } | |
| 1807 | else | |
| 1808 | {
| |
| 1809 | _ImageSize = value.Size; | |
| 1810 | } | |
| 1811 | ||
| 1812 | _Image = value; | |
| 1813 | ||
| 1814 | if (Image == null) | |
| 1815 | {
| |
| 1816 | MonoFlatTB.Location = new Point(8, 10); | |
| 1817 | } | |
| 1818 | else | |
| 1819 | {
| |
| 1820 | MonoFlatTB.Location = new Point(35, 11); | |
| 1821 | } | |
| 1822 | Invalidate(); | |
| 1823 | } | |
| 1824 | } | |
| 1825 | ||
| 1826 | protected Size ImageSize | |
| 1827 | {
| |
| 1828 | get | |
| 1829 | {
| |
| 1830 | return _ImageSize; | |
| 1831 | } | |
| 1832 | } | |
| 1833 | ||
| 1834 | #endregion | |
| 1835 | #region EventArgs | |
| 1836 | ||
| 1837 | private void _Enter(object Obj, EventArgs e) | |
| 1838 | {
| |
| 1839 | P1 = new Pen(Color.FromArgb(181, 41, 42)); | |
| 1840 | Refresh(); | |
| 1841 | } | |
| 1842 | ||
| 1843 | private void _Leave(object Obj, EventArgs e) | |
| 1844 | {
| |
| 1845 | P1 = new Pen(Color.FromArgb(32, 41, 50)); | |
| 1846 | Refresh(); | |
| 1847 | } | |
| 1848 | ||
| 1849 | private void OnBaseTextChanged(object s, EventArgs e) | |
| 1850 | {
| |
| 1851 | Text = MonoFlatTB.Text; | |
| 1852 | } | |
| 1853 | ||
| 1854 | protected override void OnTextChanged(System.EventArgs e) | |
| 1855 | {
| |
| 1856 | base.OnTextChanged(e); | |
| 1857 | MonoFlatTB.Text = Text; | |
| 1858 | Invalidate(); | |
| 1859 | } | |
| 1860 | ||
| 1861 | protected override void OnForeColorChanged(System.EventArgs e) | |
| 1862 | {
| |
| 1863 | base.OnForeColorChanged(e); | |
| 1864 | MonoFlatTB.ForeColor = ForeColor; | |
| 1865 | Invalidate(); | |
| 1866 | } | |
| 1867 | ||
| 1868 | protected override void OnFontChanged(System.EventArgs e) | |
| 1869 | {
| |
| 1870 | base.OnFontChanged(e); | |
| 1871 | MonoFlatTB.Font = Font; | |
| 1872 | } | |
| 1873 | ||
| 1874 | protected override void OnPaintBackground(PaintEventArgs e) | |
| 1875 | {
| |
| 1876 | base.OnPaintBackground(e); | |
| 1877 | } | |
| 1878 | ||
| 1879 | private void _OnKeyDown(object Obj, KeyEventArgs e) | |
| 1880 | {
| |
| 1881 | if (e.Control && e.KeyCode == Keys.A) | |
| 1882 | {
| |
| 1883 | MonoFlatTB.SelectAll(); | |
| 1884 | e.SuppressKeyPress = true; | |
| 1885 | } | |
| 1886 | if (e.Control && e.KeyCode == Keys.C) | |
| 1887 | {
| |
| 1888 | MonoFlatTB.Copy(); | |
| 1889 | e.SuppressKeyPress = true; | |
| 1890 | } | |
| 1891 | } | |
| 1892 | ||
| 1893 | protected override void OnResize(System.EventArgs e) | |
| 1894 | {
| |
| 1895 | base.OnResize(e); | |
| 1896 | if (_Multiline) | |
| 1897 | {
| |
| 1898 | MonoFlatTB.Height = Height - 23; | |
| 1899 | } | |
| 1900 | else | |
| 1901 | {
| |
| 1902 | Height = MonoFlatTB.Height + 23; | |
| 1903 | } | |
| 1904 | ||
| 1905 | Shape = new GraphicsPath(); | |
| 1906 | Shape.AddArc(0, 0, 10, 10, 180, 90); | |
| 1907 | Shape.AddArc(Width - 11, 0, 10, 10, -90, 90); | |
| 1908 | Shape.AddArc(Width - 11, Height - 11, 10, 10, 0, 90); | |
| 1909 | Shape.AddArc(0, Height - 11, 10, 10, 90, 90); | |
| 1910 | Shape.CloseAllFigures(); | |
| 1911 | } | |
| 1912 | ||
| 1913 | protected override void OnGotFocus(System.EventArgs e) | |
| 1914 | {
| |
| 1915 | base.OnGotFocus(e); | |
| 1916 | MonoFlatTB.Focus(); | |
| 1917 | } | |
| 1918 | ||
| 1919 | public void _TextChanged(System.Object sender, System.EventArgs e) | |
| 1920 | {
| |
| 1921 | Text = MonoFlatTB.Text; | |
| 1922 | } | |
| 1923 | ||
| 1924 | public void _BaseTextChanged(System.Object sender, System.EventArgs e) | |
| 1925 | {
| |
| 1926 | MonoFlatTB.Text = Text; | |
| 1927 | } | |
| 1928 | ||
| 1929 | #endregion | |
| 1930 | ||
| 1931 | public void AddTextBox() | |
| 1932 | {
| |
| 1933 | MonoFlatTB.Location = new Point(8, 10); | |
| 1934 | MonoFlatTB.Text = String.Empty; | |
| 1935 | MonoFlatTB.BorderStyle = BorderStyle.None; | |
| 1936 | MonoFlatTB.TextAlign = HorizontalAlignment.Left; | |
| 1937 | MonoFlatTB.Font = new Font("Tahoma", 11);
| |
| 1938 | MonoFlatTB.UseSystemPasswordChar = UseSystemPasswordChar; | |
| 1939 | MonoFlatTB.Multiline = false; | |
| 1940 | MonoFlatTB.BackColor = Color.FromArgb(66, 76, 85); | |
| 1941 | MonoFlatTB.ScrollBars = ScrollBars.None; | |
| 1942 | MonoFlatTB.KeyDown += _OnKeyDown; | |
| 1943 | MonoFlatTB.Enter += _Enter; | |
| 1944 | MonoFlatTB.Leave += _Leave; | |
| 1945 | MonoFlatTB.TextChanged += OnBaseTextChanged; | |
| 1946 | } | |
| 1947 | ||
| 1948 | public MonoFlat_TextBox() | |
| 1949 | {
| |
| 1950 | SetStyle(ControlStyles.SupportsTransparentBackColor, true); | |
| 1951 | SetStyle(ControlStyles.UserPaint, true); | |
| 1952 | ||
| 1953 | AddTextBox(); | |
| 1954 | Controls.Add(MonoFlatTB); | |
| 1955 | ||
| 1956 | P1 = new Pen(Color.FromArgb(32, 41, 50)); | |
| 1957 | B1 = new SolidBrush(Color.FromArgb(66, 76, 85)); | |
| 1958 | BackColor = Color.Transparent; | |
| 1959 | ForeColor = Color.FromArgb(176, 183, 191); | |
| 1960 | ||
| 1961 | Text = null; | |
| 1962 | Font = new Font("Tahoma", 11);
| |
| 1963 | Size = new Size(135, 43); | |
| 1964 | DoubleBuffered = true; | |
| 1965 | } | |
| 1966 | ||
| 1967 | protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) | |
| 1968 | {
| |
| 1969 | base.OnPaint(e); | |
| 1970 | Bitmap B = new Bitmap(Width, Height); | |
| 1971 | Graphics G = Graphics.FromImage(B); | |
| 1972 | ||
| 1973 | G.SmoothingMode = SmoothingMode.AntiAlias; | |
| 1974 | ||
| 1975 | ||
| 1976 | if (Image == null) | |
| 1977 | {
| |
| 1978 | MonoFlatTB.Width = Width - 18; | |
| 1979 | } | |
| 1980 | else | |
| 1981 | {
| |
| 1982 | MonoFlatTB.Width = Width - 45; | |
| 1983 | } | |
| 1984 | ||
| 1985 | MonoFlatTB.TextAlign = TextAlignment; | |
| 1986 | MonoFlatTB.UseSystemPasswordChar = UseSystemPasswordChar; | |
| 1987 | ||
| 1988 | G.Clear(Color.Transparent); | |
| 1989 | ||
| 1990 | G.FillPath(B1, Shape); | |
| 1991 | G.DrawPath(P1, Shape); | |
| 1992 | ||
| 1993 | if (Image != null) | |
| 1994 | {
| |
| 1995 | G.DrawImage(_Image, 5, 8, 24, 24); | |
| 1996 | // 24x24 is the perfect size of the image | |
| 1997 | } | |
| 1998 | ||
| 1999 | e.Graphics.DrawImage((Image)(B.Clone()), 0, 0); | |
| 2000 | G.Dispose(); | |
| 2001 | B.Dispose(); | |
| 2002 | } | |
| 2003 | } | |
| 2004 | ||
| 2005 | #endregion | |
| 2006 | #region Panel | |
| 2007 | ||
| 2008 | public class MonoFlat_Panel : ContainerControl | |
| 2009 | {
| |
| 2010 | ||
| 2011 | private GraphicsPath Shape; | |
| 2012 | ||
| 2013 | public MonoFlat_Panel() | |
| 2014 | {
| |
| 2015 | SetStyle(ControlStyles.SupportsTransparentBackColor, true); | |
| 2016 | SetStyle(ControlStyles.UserPaint, true); | |
| 2017 | ||
| 2018 | BackColor = Color.FromArgb(39, 51, 63); | |
| 2019 | this.Size = new Size(187, 117); | |
| 2020 | Padding = new Padding(5, 5, 5, 5); | |
| 2021 | DoubleBuffered = true; | |
| 2022 | } | |
| 2023 | ||
| 2024 | protected override void OnResize(System.EventArgs e) | |
| 2025 | {
| |
| 2026 | base.OnResize(e); | |
| 2027 | ||
| 2028 | Shape = new GraphicsPath(); | |
| 2029 | Shape.AddArc(0, 0, 10, 10, 180, 90); | |
| 2030 | Shape.AddArc(Width - 11, 0, 10, 10, -90, 90); | |
| 2031 | Shape.AddArc(Width - 11, Height - 11, 10, 10, 0, 90); | |
| 2032 | Shape.AddArc(0, Height - 11, 10, 10, 90, 90); | |
| 2033 | Shape.CloseAllFigures(); | |
| 2034 | } | |
| 2035 | ||
| 2036 | protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) | |
| 2037 | {
| |
| 2038 | base.OnPaint(e); | |
| 2039 | Bitmap B = new Bitmap(Width, Height); | |
| 2040 | var G = Graphics.FromImage(B); | |
| 2041 | ||
| 2042 | G.SmoothingMode = SmoothingMode.HighQuality; | |
| 2043 | ||
| 2044 | G.Clear(Color.FromArgb(32, 41, 50)); // Set control background to transparent | |
| 2045 | G.FillPath(new SolidBrush(Color.FromArgb(39, 51, 63)), Shape); // Draw RTB background | |
| 2046 | G.DrawPath(new Pen(Color.FromArgb(39, 51, 63)), Shape); // Draw border | |
| 2047 | ||
| 2048 | G.Dispose(); | |
| 2049 | e.Graphics.DrawImage((Image)(B.Clone()), 0, 0); | |
| 2050 | B.Dispose(); | |
| 2051 | } | |
| 2052 | } | |
| 2053 | ||
| 2054 | #endregion | |
| 2055 | #region Separator | |
| 2056 | ||
| 2057 | public class MonoFlat_Separator : Control | |
| 2058 | {
| |
| 2059 | ||
| 2060 | public MonoFlat_Separator() | |
| 2061 | {
| |
| 2062 | SetStyle(ControlStyles.ResizeRedraw, true); | |
| 2063 | this.Size = (System.Drawing.Size)(new Point(120, 10)); | |
| 2064 | } | |
| 2065 | ||
| 2066 | protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) | |
| 2067 | {
| |
| 2068 | base.OnPaint(e); | |
| 2069 | e.Graphics.DrawLine(new Pen(Color.FromArgb(45, 57, 68)), 0, 5, Width, 5); | |
| 2070 | } | |
| 2071 | } | |
| 2072 | ||
| 2073 | #endregion | |
| 2074 | #region TrackBar | |
| 2075 | ||
| 2076 | [DefaultEvent("ValueChanged")]
| |
| 2077 | public class MonoFlat_TrackBar : Control | |
| 2078 | {
| |
| 2079 | ||
| 2080 | #region Enums | |
| 2081 | ||
| 2082 | public enum ValueDivisor | |
| 2083 | {
| |
| 2084 | By1 = 1, | |
| 2085 | By10 = 10, | |
| 2086 | By100 = 100, | |
| 2087 | By1000 = 1000 | |
| 2088 | } | |
| 2089 | ||
| 2090 | #endregion | |
| 2091 | #region Variables | |
| 2092 | ||
| 2093 | private Rectangle FillValue; | |
| 2094 | private Rectangle PipeBorder; | |
| 2095 | private Rectangle TrackBarHandleRect; | |
| 2096 | private bool Cap; | |
| 2097 | private int ValueDrawer; | |
| 2098 | ||
| 2099 | private Size ThumbSize = new Size(14, 14); | |
| 2100 | private Rectangle TrackThumb; | |
| 2101 | ||
| 2102 | private int _Minimum = 0; | |
| 2103 | private int _Maximum = 10; | |
| 2104 | private int _Value = 0; | |
| 2105 | ||
| 2106 | private bool _JumpToMouse = false; | |
| 2107 | private ValueDivisor DividedValue = ValueDivisor.By1; | |
| 2108 | ||
| 2109 | #endregion | |
| 2110 | #region Properties | |
| 2111 | ||
| 2112 | public int Minimum | |
| 2113 | {
| |
| 2114 | get | |
| 2115 | {
| |
| 2116 | return _Minimum; | |
| 2117 | } | |
| 2118 | set | |
| 2119 | {
| |
| 2120 | ||
| 2121 | if (value >= _Maximum) | |
| 2122 | {
| |
| 2123 | value = _Maximum - 10; | |
| 2124 | } | |
| 2125 | if (_Value < value) | |
| 2126 | {
| |
| 2127 | _Value = value; | |
| 2128 | } | |
| 2129 | ||
| 2130 | _Minimum = value; | |
| 2131 | Invalidate(); | |
| 2132 | } | |
| 2133 | } | |
| 2134 | ||
| 2135 | public int Maximum | |
| 2136 | {
| |
| 2137 | get | |
| 2138 | {
| |
| 2139 | return _Maximum; | |
| 2140 | } | |
| 2141 | set | |
| 2142 | {
| |
| 2143 | ||
| 2144 | if (value <= _Minimum) | |
| 2145 | {
| |
| 2146 | value = _Minimum + 10; | |
| 2147 | } | |
| 2148 | if (_Value > value) | |
| 2149 | {
| |
| 2150 | _Value = value; | |
| 2151 | } | |
| 2152 | ||
| 2153 | _Maximum = value; | |
| 2154 | Invalidate(); | |
| 2155 | } | |
| 2156 | } | |
| 2157 | ||
| 2158 | public delegate void ValueChangedEventHandler(); | |
| 2159 | private ValueChangedEventHandler ValueChangedEvent; | |
| 2160 | ||
| 2161 | public event ValueChangedEventHandler ValueChanged | |
| 2162 | {
| |
| 2163 | add | |
| 2164 | {
| |
| 2165 | ValueChangedEvent = (ValueChangedEventHandler)System.Delegate.Combine(ValueChangedEvent, value); | |
| 2166 | } | |
| 2167 | remove | |
| 2168 | {
| |
| 2169 | ValueChangedEvent = (ValueChangedEventHandler)System.Delegate.Remove(ValueChangedEvent, value); | |
| 2170 | } | |
| 2171 | } | |
| 2172 | ||
| 2173 | public int Value | |
| 2174 | {
| |
| 2175 | get | |
| 2176 | {
| |
| 2177 | return _Value; | |
| 2178 | } | |
| 2179 | set | |
| 2180 | {
| |
| 2181 | if (_Value != value) | |
| 2182 | {
| |
| 2183 | if (value < _Minimum) | |
| 2184 | {
| |
| 2185 | _Value = _Minimum; | |
| 2186 | } | |
| 2187 | else | |
| 2188 | {
| |
| 2189 | if (value > _Maximum) | |
| 2190 | {
| |
| 2191 | _Value = _Maximum; | |
| 2192 | } | |
| 2193 | else | |
| 2194 | {
| |
| 2195 | _Value = value; | |
| 2196 | } | |
| 2197 | } | |
| 2198 | Invalidate(); | |
| 2199 | if (ValueChangedEvent != null) | |
| 2200 | ValueChangedEvent(); | |
| 2201 | } | |
| 2202 | } | |
| 2203 | } | |
| 2204 | ||
| 2205 | public ValueDivisor ValueDivison | |
| 2206 | {
| |
| 2207 | get | |
| 2208 | {
| |
| 2209 | return DividedValue; | |
| 2210 | } | |
| 2211 | set | |
| 2212 | {
| |
| 2213 | DividedValue = value; | |
| 2214 | Invalidate(); | |
| 2215 | } | |
| 2216 | } | |
| 2217 | ||
| 2218 | [Browsable(false)] | |
| 2219 | public float ValueToSet | |
| 2220 | {
| |
| 2221 | get | |
| 2222 | {
| |
| 2223 | return _Value / (int)DividedValue; | |
| 2224 | } | |
| 2225 | set | |
| 2226 | {
| |
| 2227 | Value = (int)(value * (int)DividedValue); | |
| 2228 | } | |
| 2229 | } | |
| 2230 | ||
| 2231 | public bool JumpToMouse | |
| 2232 | {
| |
| 2233 | get | |
| 2234 | {
| |
| 2235 | return _JumpToMouse; | |
| 2236 | } | |
| 2237 | set | |
| 2238 | {
| |
| 2239 | _JumpToMouse = value; | |
| 2240 | Invalidate(); | |
| 2241 | } | |
| 2242 | } | |
| 2243 | ||
| 2244 | #endregion | |
| 2245 | #region EventArgs | |
| 2246 | ||
| 2247 | protected override void OnMouseMove(MouseEventArgs e) | |
| 2248 | {
| |
| 2249 | base.OnMouseMove(e); | |
| 2250 | checked | |
| 2251 | {
| |
| 2252 | bool flag = this.Cap && e.X > -1 && e.X < this.Width + 1; | |
| 2253 | if (flag) | |
| 2254 | {
| |
| 2255 | this.Value = this._Minimum + (int)Math.Round((double)(this._Maximum - this._Minimum) * ((double)e.X / (double)this.Width)); | |
| 2256 | } | |
| 2257 | } | |
| 2258 | } | |
| 2259 | ||
| 2260 | protected override void OnMouseDown(MouseEventArgs e) | |
| 2261 | {
| |
| 2262 | base.OnMouseDown(e); | |
| 2263 | if (e.Button == MouseButtons.Left) | |
| 2264 | {
| |
| 2265 | this.ValueDrawer = (int)Math.Round(((double)(this._Value - this._Minimum) / (double)(this._Maximum - this._Minimum)) * (double)(this.Width - 11)); | |
| 2266 | TrackBarHandleRect = new Rectangle(ValueDrawer, 0, 25, 25); | |
| 2267 | Cap = TrackBarHandleRect.Contains(e.Location); | |
| 2268 | Focus(); | |
| 2269 | if (_JumpToMouse) | |
| 2270 | {
| |
| 2271 | this.Value = this._Minimum + (int)Math.Round((double)(this._Maximum - this._Minimum) * ((double)e.X / (double)this.Width)); | |
| 2272 | } | |
| 2273 | } | |
| 2274 | } | |
| 2275 | ||
| 2276 | protected override void OnMouseUp(MouseEventArgs e) | |
| 2277 | {
| |
| 2278 | base.OnMouseUp(e); | |
| 2279 | Cap = false; | |
| 2280 | } | |
| 2281 | ||
| 2282 | #endregion | |
| 2283 | ||
| 2284 | public MonoFlat_TrackBar() | |
| 2285 | {
| |
| 2286 | SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer), true); | |
| 2287 | ||
| 2288 | Size = new Size(80, 22); | |
| 2289 | MinimumSize = new Size(47, 22); | |
| 2290 | } | |
| 2291 | ||
| 2292 | protected override void OnResize(EventArgs e) | |
| 2293 | {
| |
| 2294 | base.OnResize(e); | |
| 2295 | Height = 22; | |
| 2296 | } | |
| 2297 | ||
| 2298 | protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) | |
| 2299 | {
| |
| 2300 | base.OnPaint(e); | |
| 2301 | Graphics G = e.Graphics; | |
| 2302 | ||
| 2303 | G.Clear(Parent.BackColor); | |
| 2304 | G.SmoothingMode = SmoothingMode.AntiAlias; | |
| 2305 | TrackThumb = new Rectangle(7, 10, Width - 16, 2); | |
| 2306 | PipeBorder = new Rectangle(1, 10, Width - 3, 2); | |
| 2307 | ||
| 2308 | try | |
| 2309 | {
| |
| 2310 | this.ValueDrawer = (int)Math.Round(((double)(this._Value - this._Minimum) / (double)(this._Maximum - this._Minimum)) * (double)(this.Width)); | |
| 2311 | } | |
| 2312 | catch (Exception) | |
| 2313 | {
| |
| 2314 | } | |
| 2315 | ||
| 2316 | TrackBarHandleRect = new Rectangle(ValueDrawer, 0, 3, 20); | |
| 2317 | ||
| 2318 | G.FillRectangle(new SolidBrush(Color.FromArgb(124, 131, 137)), PipeBorder); | |
| 2319 | FillValue = new Rectangle(0, 10, TrackBarHandleRect.X + TrackBarHandleRect.Width - 4, 3); | |
| 2320 | ||
| 2321 | G.ResetClip(); | |
| 2322 | ||
| 2323 | G.SmoothingMode = SmoothingMode.Default; | |
| 2324 | G.DrawRectangle(new Pen(Color.FromArgb(124, 131, 137)), PipeBorder); // Draw pipe border | |
| 2325 | G.FillRectangle(new SolidBrush(Color.FromArgb(181, 41, 42)), FillValue); | |
| 2326 | ||
| 2327 | G.ResetClip(); | |
| 2328 | ||
| 2329 | G.SmoothingMode = SmoothingMode.HighQuality; | |
| 2330 | ||
| 2331 | G.FillEllipse(new SolidBrush(Color.FromArgb(181, 41, 42)), this.TrackThumb.X + (int)Math.Round(unchecked((double)this.TrackThumb.Width * ((double)this.Value / (double)this.Maximum))) - (int)Math.Round((double)this.ThumbSize.Width / 2.0), this.TrackThumb.Y + (int)Math.Round((double)this.TrackThumb.Height / 2.0) - (int)Math.Round((double)this.ThumbSize.Height / 2.0), this.ThumbSize.Width, this.ThumbSize.Height); | |
| 2332 | G.DrawEllipse(new Pen(Color.FromArgb(181, 41, 42)), this.TrackThumb.X + (int)Math.Round(unchecked((double)this.TrackThumb.Width * ((double)this.Value / (double)this.Maximum))) - (int)Math.Round((double)this.ThumbSize.Width / 2.0), this.TrackThumb.Y + (int)Math.Round((double)this.TrackThumb.Height / 2.0) - (int)Math.Round((double)this.ThumbSize.Height / 2.0), this.ThumbSize.Width, this.ThumbSize.Height); | |
| 2333 | } | |
| 2334 | } | |
| 2335 | ||
| 2336 | #endregion | |
| 2337 | #region NotificationBox | |
| 2338 | ||
| 2339 | public class MonoFlat_NotificationBox : Control | |
| 2340 | {
| |
| 2341 | ||
| 2342 | #region Variables | |
| 2343 | ||
| 2344 | private Point CloseCoordinates; | |
| 2345 | private bool IsOverClose; | |
| 2346 | private int _BorderCurve = 8; | |
| 2347 | private GraphicsPath CreateRoundPath; | |
| 2348 | private string NotificationText = null; | |
| 2349 | private Type _NotificationType; | |
| 2350 | private bool _RoundedCorners; | |
| 2351 | private bool _ShowCloseButton; | |
| 2352 | private Image _Image; | |
| 2353 | private Size _ImageSize; | |
| 2354 | ||
| 2355 | #endregion | |
| 2356 | #region Enums | |
| 2357 | ||
| 2358 | // Create a list of Notification Types | |
| 2359 | public enum Type | |
| 2360 | {
| |
| 2361 | @Notice, | |
| 2362 | @Success, | |
| 2363 | @Warning, | |
| 2364 | @Error | |
| 2365 | } | |
| 2366 | ||
| 2367 | #endregion | |
| 2368 | #region Custom Properties | |
| 2369 | ||
| 2370 | // Create a NotificationType property and add the Type enum to it | |
| 2371 | public Type NotificationType | |
| 2372 | {
| |
| 2373 | get | |
| 2374 | {
| |
| 2375 | return _NotificationType; | |
| 2376 | } | |
| 2377 | set | |
| 2378 | {
| |
| 2379 | _NotificationType = value; | |
| 2380 | Invalidate(); | |
| 2381 | } | |
| 2382 | } | |
| 2383 | // Boolean value to determine whether the control should use border radius | |
| 2384 | public bool RoundCorners | |
| 2385 | {
| |
| 2386 | get | |
| 2387 | {
| |
| 2388 | return _RoundedCorners; | |
| 2389 | } | |
| 2390 | set | |
| 2391 | {
| |
| 2392 | _RoundedCorners = value; | |
| 2393 | Invalidate(); | |
| 2394 | } | |
| 2395 | } | |
| 2396 | // Boolean value to determine whether the control should draw the close button | |
| 2397 | public bool ShowCloseButton | |
| 2398 | {
| |
| 2399 | get | |
| 2400 | {
| |
| 2401 | return _ShowCloseButton; | |
| 2402 | } | |
| 2403 | set | |
| 2404 | {
| |
| 2405 | _ShowCloseButton = value; | |
| 2406 | Invalidate(); | |
| 2407 | } | |
| 2408 | } | |
| 2409 | // Integer value to determine the curve level of the borders | |
| 2410 | public int BorderCurve | |
| 2411 | {
| |
| 2412 | get | |
| 2413 | {
| |
| 2414 | return _BorderCurve; | |
| 2415 | } | |
| 2416 | set | |
| 2417 | {
| |
| 2418 | _BorderCurve = value; | |
| 2419 | Invalidate(); | |
| 2420 | } | |
| 2421 | } | |
| 2422 | // Image value to determine whether the control should draw an image before the header | |
| 2423 | public Image Image | |
| 2424 | {
| |
| 2425 | get | |
| 2426 | {
| |
| 2427 | return _Image; | |
| 2428 | } | |
| 2429 | set | |
| 2430 | {
| |
| 2431 | if (value == null) | |
| 2432 | {
| |
| 2433 | _ImageSize = Size.Empty; | |
| 2434 | } | |
| 2435 | else | |
| 2436 | {
| |
| 2437 | _ImageSize = value.Size; | |
| 2438 | } | |
| 2439 | ||
| 2440 | _Image = value; | |
| 2441 | Invalidate(); | |
| 2442 | } | |
| 2443 | } | |
| 2444 | // Size value - returns the image size | |
| 2445 | protected Size ImageSize | |
| 2446 | {
| |
| 2447 | get | |
| 2448 | {
| |
| 2449 | return _ImageSize; | |
| 2450 | } | |
| 2451 | } | |
| 2452 | ||
| 2453 | #endregion | |
| 2454 | #region EventArgs | |
| 2455 | ||
| 2456 | protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) | |
| 2457 | {
| |
| 2458 | base.OnMouseMove(e); | |
| 2459 | ||
| 2460 | // Decides the location of the drawn ellipse. If mouse is over the correct coordinates, "IsOverClose" boolean will be triggered to draw the ellipse | |
| 2461 | if (e.X >= Width - 19 && e.X <= Width - 10 && e.Y > CloseCoordinates.Y && e.Y < CloseCoordinates.Y + 12) | |
| 2462 | {
| |
| 2463 | IsOverClose = true; | |
| 2464 | } | |
| 2465 | else | |
| 2466 | {
| |
| 2467 | IsOverClose = false; | |
| 2468 | } | |
| 2469 | // Updates the control | |
| 2470 | Invalidate(); | |
| 2471 | } | |
| 2472 | protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) | |
| 2473 | {
| |
| 2474 | base.OnMouseDown(e); | |
| 2475 | ||
| 2476 | // Disposes the control when the close button is clicked | |
| 2477 | if (_ShowCloseButton == true) | |
| 2478 | {
| |
| 2479 | if (IsOverClose) | |
| 2480 | {
| |
| 2481 | Dispose(); | |
| 2482 | } | |
| 2483 | } | |
| 2484 | } | |
| 2485 | ||
| 2486 | #endregion | |
| 2487 | ||
| 2488 | internal GraphicsPath CreateRoundRect(Rectangle r, int curve) | |
| 2489 | {
| |
| 2490 | // Draw a border radius | |
| 2491 | try | |
| 2492 | {
| |
| 2493 | CreateRoundPath = new GraphicsPath(FillMode.Winding); | |
| 2494 | CreateRoundPath.AddArc(r.X, r.Y, curve, curve, 180.0F, 90.0F); | |
| 2495 | CreateRoundPath.AddArc(r.Right - curve, r.Y, curve, curve, 270.0F, 90.0F); | |
| 2496 | CreateRoundPath.AddArc(r.Right - curve, r.Bottom - curve, curve, curve, 0.0F, 90.0F); | |
| 2497 | CreateRoundPath.AddArc(r.X, r.Bottom - curve, curve, curve, 90.0F, 90.0F); | |
| 2498 | CreateRoundPath.CloseFigure(); | |
| 2499 | } | |
| 2500 | catch (Exception ex) | |
| 2501 | {
| |
| 2502 | MessageBox.Show(ex.Message + Environment.NewLine + Environment.NewLine + "Value must be either \'1\' or higher", "Invalid Integer", MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
| 2503 | // Return to the default border curve if the parameter is less than "1" | |
| 2504 | _BorderCurve = 8; | |
| 2505 | BorderCurve = 8; | |
| 2506 | } | |
| 2507 | return CreateRoundPath; | |
| 2508 | } | |
| 2509 | ||
| 2510 | public MonoFlat_NotificationBox() | |
| 2511 | {
| |
| 2512 | SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw), true); | |
| 2513 | ||
| 2514 | Font = new Font("Tahoma", 9);
| |
| 2515 | this.MinimumSize = new Size(100, 40); | |
| 2516 | RoundCorners = false; | |
| 2517 | ShowCloseButton = true; | |
| 2518 | } | |
| 2519 | ||
| 2520 | protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) | |
| 2521 | {
| |
| 2522 | base.OnPaint(e); | |
| 2523 | ||
| 2524 | // Declare Graphics to draw the control | |
| 2525 | Graphics GFX = e.Graphics; | |
| 2526 | // Declare Color to paint the control's Text, Background and Border | |
| 2527 | Color ForeColor = new Color(); | |
| 2528 | Color BackgroundColor = new Color(); | |
| 2529 | Color BorderColor = new Color(); | |
| 2530 | // Determine the header Notification Type font | |
| 2531 | Font TypeFont = new Font(Font.FontFamily, Font.Size, FontStyle.Bold); | |
| 2532 | // Decalre a new rectangle to draw the control inside it | |
| 2533 | Rectangle MainRectangle = new Rectangle(0, 0, Width - 1, Height - 1); | |
| 2534 | // Declare a GraphicsPath to create a border radius | |
| 2535 | GraphicsPath CrvBorderPath = CreateRoundRect(MainRectangle, _BorderCurve); | |
| 2536 | ||
| 2537 | GFX.SmoothingMode = SmoothingMode.HighQuality; | |
| 2538 | GFX.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; | |
| 2539 | GFX.Clear(Parent.BackColor); | |
| 2540 | ||
| 2541 | switch (_NotificationType) | |
| 2542 | {
| |
| 2543 | case Type.Notice: | |
| 2544 | BackgroundColor = Color.FromArgb(111, 177, 199); | |
| 2545 | BorderColor = Color.FromArgb(111, 177, 199); | |
| 2546 | ForeColor = Color.White; | |
| 2547 | break; | |
| 2548 | case Type.Success: | |
| 2549 | BackgroundColor = Color.FromArgb(91, 195, 162); | |
| 2550 | BorderColor = Color.FromArgb(91, 195, 162); | |
| 2551 | ForeColor = Color.White; | |
| 2552 | break; | |
| 2553 | case Type.Warning: | |
| 2554 | BackgroundColor = Color.FromArgb(254, 209, 108); | |
| 2555 | BorderColor = Color.FromArgb(254, 209, 108); | |
| 2556 | ForeColor = Color.DimGray; | |
| 2557 | break; | |
| 2558 | case Type.Error: | |
| 2559 | BackgroundColor = Color.FromArgb(217, 103, 93); | |
| 2560 | BorderColor = Color.FromArgb(217, 103, 93); | |
| 2561 | ForeColor = Color.White; | |
| 2562 | break; | |
| 2563 | } | |
| 2564 | ||
| 2565 | if (_RoundedCorners == true) | |
| 2566 | {
| |
| 2567 | GFX.FillPath(new SolidBrush(BackgroundColor), CrvBorderPath); | |
| 2568 | GFX.DrawPath(new Pen(BorderColor), CrvBorderPath); | |
| 2569 | } | |
| 2570 | else | |
| 2571 | {
| |
| 2572 | GFX.FillRectangle(new SolidBrush(BackgroundColor), MainRectangle); | |
| 2573 | GFX.DrawRectangle(new Pen(BorderColor), MainRectangle); | |
| 2574 | } | |
| 2575 | ||
| 2576 | switch (_NotificationType) | |
| 2577 | {
| |
| 2578 | case Type.Notice: | |
| 2579 | NotificationText = "NOTICE"; | |
| 2580 | break; | |
| 2581 | case Type.Success: | |
| 2582 | NotificationText = "SUCCESS"; | |
| 2583 | break; | |
| 2584 | case Type.Warning: | |
| 2585 | NotificationText = "WARNING"; | |
| 2586 | break; | |
| 2587 | case Type.Error: | |
| 2588 | NotificationText = "ERROR"; | |
| 2589 | break; | |
| 2590 | } | |
| 2591 | ||
| 2592 | if (Image == null) | |
| 2593 | {
| |
| 2594 | GFX.DrawString(NotificationText, TypeFont, new SolidBrush(ForeColor), new Point(10, 5)); | |
| 2595 | GFX.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(10, 21, Width - 17, Height - 5)); | |
| 2596 | } | |
| 2597 | else | |
| 2598 | {
| |
| 2599 | GFX.DrawImage(_Image, 12, 4, 16, 16); | |
| 2600 | GFX.DrawString(NotificationText, TypeFont, new SolidBrush(ForeColor), new Point(30, 5)); | |
| 2601 | GFX.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(10, 21, Width - 17, Height - 5)); | |
| 2602 | } | |
| 2603 | ||
| 2604 | CloseCoordinates = new Point(Width - 26, 4); | |
| 2605 | ||
| 2606 | if (_ShowCloseButton == true) | |
| 2607 | {
| |
| 2608 | // Draw the close button | |
| 2609 | GFX.DrawString("r", new Font("Marlett", 7, FontStyle.Regular), new SolidBrush(Color.FromArgb(130, 130, 130)), new Rectangle(Width - 20, 10, Width, Height), new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near });
| |
| 2610 | } | |
| 2611 | ||
| 2612 | CrvBorderPath.Dispose(); | |
| 2613 | } | |
| 2614 | } | |
| 2615 | ||
| 2616 | #endregion | |
| 2617 | ||
| 2618 | } |