GroupBoxWithBorder.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. namespace UAS_LabelMachine.CustomControl.GroupBoxWithBorder
  4. {
  5. public partial class GroupBoxWithBorder : GroupBox
  6. {
  7. public GroupBoxWithBorder()
  8. {
  9. InitializeComponent();
  10. this.Paint += this.groupBox1_Paint;
  11. }
  12. private void groupBox1_Paint(object sender, PaintEventArgs e)
  13. {
  14. try
  15. {
  16. e.Graphics.Clear(this.BackColor);
  17. e.Graphics.DrawString(this.Text, this.Font, Brushes.Black, 10, 1);
  18. Pen LineColor = Pens.Gray;
  19. e.Graphics.DrawLine(LineColor, 1, 7, 8, 7);
  20. e.Graphics.DrawLine(LineColor, e.Graphics.MeasureString(this.Text, this.Font).Width + 8, 7, this.Width - 2, 7);
  21. e.Graphics.DrawLine(LineColor, 1, 7, 1, this.Height - 2);
  22. e.Graphics.DrawLine(LineColor, 1, this.Height - 2, this.Width - 2, this.Height - 2);
  23. e.Graphics.DrawLine(LineColor, this.Width - 2, 7, this.Width - 2, this.Height - 2);
  24. }
  25. catch (System.Exception)
  26. {
  27. }
  28. }
  29. }
  30. }