2013-02-01 7 views
3

가능한 복제를 경계 변경 :
How can I change the border thickness of a Groupbox on a windows form in C#?는 그룹 상자 구성 요소에서

얘들 아 내가 비주얼 스튜디오에서 '그룹 상자를 사용하고

. 그러나 그룹 박스의 테두리는 작습니다. 테두리 나 색상을 지정하여 테두리를 편집하는 방법이 있는지 궁금합니다. u는 화상에서 볼 수 있듯이

enter image description here

주위 경계를 보는 것은 매우 어렵다.

아무도 도와 줄 수 있습니까?

+1

http://stackoverflow.com/questions/10997977/how-can-i-change-the-border-thickness-of-a-groupbox-on-a-windows-form-in-c –

+0

이것을 확인하십시오 : https://social.msdn.microsoft.com/Forums/windows/en-US/cfd34dd1-b6e5-4b56-9901-0dc3d2ca5788/changing-border-color-of-groupbox?forum=winforms – Mohammadreza

답변

4

당신은이를 사용할 수 있습니다

using System.Drawing; 

System.Drawing.Drawing2D를 사용하여;

private void Form1_Load(object sender, EventArgs e) 
    { 
     myGroupBox myGroupBox = new myGroupBox(); 
     myGroupBox.Text = "GroupBox1"; 

     this.Controls.Add(myGroupBox); 

    } 




    public static GraphicsPath CreatePath(float x, float y, float width, float height, 
            float radius, bool RoundTopLeft, bool RoundTopRight, bool RoundBottomRight, bool RoundBottomLeft) 
    { 
     float xw = x + width; 
     float yh = y + height; 
     float xwr = xw - radius; 
     float yhr = yh - radius; 
     float xr = x + radius; 
     float yr = y + radius; 
     float r2 = radius * 2; 
     float xwr2 = xw - r2; 
     float yhr2 = yh - r2; 

     GraphicsPath p = new GraphicsPath(); 
     p.StartFigure(); 

     //Top Left Corner 

     if (RoundTopLeft) 
     { 
      p.AddArc(x, y, r2, r2, 180, 90); 
     } 
     else 
     { 
      p.AddLine(x, yr, x, y); 
      p.AddLine(x, y, xr, y); 

     } 

     //Top Edge 
     p.AddLine(xr, y, xwr, y); 

     //Top Right Corner 

     if (RoundTopRight) 
     { 
      p.AddArc(xwr2, y, r2, r2, 270, 90); 
     } 
     else 
     { 
      p.AddLine(xwr, y, xw, y); 
      p.AddLine(xw, y, xw, yr); 
     } 


     //Right Edge 
     p.AddLine(xw, yr, xw, yhr); 

     //Bottom Right Corner 

     if (RoundBottomRight) 
     { 
      p.AddArc(xwr2, yhr2, r2, r2, 0, 90); 
     } 
     else 
     { 
      p.AddLine(xw, yhr, xw, yh); 
      p.AddLine(xw, yh, xwr, yh); 
     } 


     //Bottom Edge 
     p.AddLine(xwr, yh, xr, yh); 

     //Bottom Left Corner   

     if (RoundBottomLeft) 
     { 
      p.AddArc(x, yhr2, r2, r2, 90, 90); 
     } 
     else 
     { 
      p.AddLine(xr, yh, x, yh); 
      p.AddLine(x, yh, x, yhr); 
     } 

     //Left Edge 
     p.AddLine(x, yhr, x, yr); 

     p.CloseFigure(); 
     return p; 
    } 


    class myGroupBox : GroupBox 
    { 
     public myGroupBox() 
     { 
      base.BackColor = Color.Transparent; 

     } 
     [Browsable(false)] 
     public override Color BackColor 
     { 
      get 
      { 
       return base.BackColor; 
      } 
      set 
      { 
       base.BackColor = value; 
      } 
     } 

     private Color backColor = Color.Transparent; 

     public Color ActualBackColor 
     { 
      get { return this.backColor; } 

      set { this.backColor = value; } 
     } 

     protected override void OnPaint(PaintEventArgs e) 
     { 

      Size tSize = TextRenderer.MeasureText(this.Text, this.Font); 

      Rectangle borderRect = e.ClipRectangle; 

      borderRect.Y += tSize.Height/2; 

      borderRect.Height -= tSize.Height/2; 

      GraphicsPath gPath = CreatePath(0, borderRect.Y, (float)(this.Width - 1), borderRect.Height - 1, 5, true, true, true, true); 

      e.Graphics.FillPath(new SolidBrush(ActualBackColor), gPath); 

      e.Graphics.DrawPath(new Pen(Color.Red), gPath); 

      borderRect.X += 6; 
      borderRect.Y -= 7; 

      e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), borderRect); 
     } 
    } 
관련 문제