VB.NET
VB.NET Panel의 Border 색상 바꾸기
악마성
2019. 8. 20. 16:22
728x90
반응형
Winform 환경에서
다른 Control에서는 Border Color를 설정할 수 있을지는 몰라도 Panel은
border Color를 별도로 설정할 수 없다..
깔끔하게 UI를 잡아주려면 Border Line Color를 Gray색상으로 하고 싶을 경우가 있는데
이럴 때 Graphics.DrawRectangle Method를 사용하여 직접 그릴 수 있다.
참조자료.
방법
① 폼에 Panel 두 개를 추가한다.
② Panel1 을 색칠한다.
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
'// Panel의 Border Style 지정
Panel1.BorderStyle = BorderStyle.FixedSingle
'// Panel1의 BorderStyle을 Pen으로 직접 그림.
'// RGB Color인데 (0,0,0,0) 인 이유는 맨 앞 0은 Opacity
'// Pen(color, x) x는 펜의 굵기.
e.Graphics.DrawRectangle(New Pen(Color.FromArgb(100, 255, 0, 0), 5), Panel1.ClientRectangle)
End Sub
③ Panel2를 색칠한다.
Private Sub Panel2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint
' Panel의 Border Style 지정
Panel2.BorderStyle = BorderStyle.FixedSingle
'// Panel의 BorderStyle을 Pen으로 직접 그림.
'// RGB Color인데 (0,0,0,0) 인 이유는 맨 앞 0은 Opacity
'// Pen(color, x) x는 펜의 굵기.
e.Graphics.DrawRectangle(New Pen(Color.FromArgb(100, 0, 255, 0), 5), Panel2.ClientRectangle)
End Sub
④ 실행해서 확인 해본다.
728x90
반응형