You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.9 KiB

1 month ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace Customize.Controls
  11. {
  12. public class ExtendedPanel : Panel
  13. {
  14. private const int WS_EX_TRANSPARENT = 0x20;
  15. public ExtendedPanel()
  16. {
  17. SetStyle(ControlStyles.Opaque, true);
  18. }
  19. private int opacity = 50;
  20. [DefaultValue(50)]
  21. public int Opacity
  22. {
  23. get
  24. {
  25. return this.opacity;
  26. }
  27. set
  28. {
  29. if (value < 0 || value > 100)
  30. throw new ArgumentException("value must be between 0 and 100");
  31. this.opacity = value;
  32. }
  33. }
  34. private string mode = "default";
  35. [DefaultValue("default")]
  36. public string Mode
  37. {
  38. get
  39. {
  40. return this.mode;
  41. }
  42. set
  43. {
  44. this.mode = value;
  45. }
  46. }
  47. protected override CreateParams CreateParams
  48. {
  49. get
  50. {
  51. CreateParams cp = base.CreateParams;
  52. cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT;
  53. return cp;
  54. }
  55. }
  56. protected override void OnPaint(PaintEventArgs e)
  57. {
  58. using (var brush = new SolidBrush(Color.FromArgb(this.opacity * 255 / 100, this.BackColor)))
  59. {
  60. Pen p = new Pen(Color.Red, 2);
  61. if (this.mode == "text")
  62. {
  63. p.DashStyle = DashStyle.Dot;
  64. }
  65. e.Graphics.FillRectangle(brush, this.ClientRectangle);
  66. e.Graphics.DrawRectangle(p, this.ClientRectangle);
  67. }
  68. base.OnPaint(e);
  69. }
  70. }
  71. }