GroupBoxwithborder.cs 1.9 KB

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