GroupBoxWithBorder.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.ComponentModel;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace UAS_MES_NEW.CustomControl.GroupBoxWithBorder
  5. {
  6. public partial class GroupBoxWithBorder : GroupBox
  7. {
  8. /// <summary>
  9. /// 获取和设置控件高亮色
  10. /// </summary>
  11. /// <value>高亮色</value>
  12. [TypeConverter("System.Drawing.ColorConverter"),
  13. Category("LoadingCircle"),
  14. Description("获取和设置控件高亮色")]
  15. public Color TextColor
  16. {
  17. get
  18. {
  19. return textcolor;
  20. }
  21. set
  22. {
  23. textcolor = value;
  24. Invalidate();
  25. }
  26. }
  27. public Color BorderColor
  28. {
  29. get
  30. {
  31. return bordercolor;
  32. }
  33. set
  34. {
  35. bordercolor = value;
  36. Invalidate();
  37. }
  38. }
  39. private Color textcolor;
  40. private Color bordercolor;
  41. public GroupBoxWithBorder()
  42. {
  43. InitializeComponent();
  44. this.Paint += this.groupBox1_Paint;
  45. }
  46. private void groupBox1_Paint(object sender, PaintEventArgs e)
  47. {
  48. e.Graphics.Clear(BackColor);
  49. Brush br = new SolidBrush(textcolor);
  50. e.Graphics.DrawString(Text, Font, br, 10, 1);
  51. Pen LineColor = new Pen(bordercolor);
  52. e.Graphics.DrawLine(LineColor, 1, 7, 8, 7);
  53. e.Graphics.DrawLine(LineColor, e.Graphics.MeasureString(Text, Font).Width + 8, 7, Width - 2, 7);
  54. e.Graphics.DrawLine(LineColor, 1, 7, 1, Height - 2);
  55. e.Graphics.DrawLine(LineColor, 1, Height - 2, Width - 2, Height - 2);
  56. e.Graphics.DrawLine(LineColor, Width - 2, 7, Width - 2, Height - 2);
  57. }
  58. }
  59. }