Change border color on panel control?

D

Dave Veeneman

Is there any simple way to change the color of a fisxed-single border on a
Panel control? The border color is black; I want to change it to
SystemColors.Highlight to match the borders on the other controls on the
form. Thanks

Dave Veeneman
Foresight Systems, Inc.
 
H

Herfried K. Wagner [MVP]

* "Dave Veeneman said:
Is there any simple way to change the color of a fisxed-single border on a
Panel control? The border color is black; I want to change it to
SystemColors.Highlight to match the borders on the other controls on the
form.

Don't show a border at all and draw it yourself:

Quick and Dirty:

\\\
Private m_lb As System.Drawing.Drawing2D.LinearGradientBrush

Private Sub Form1_Load(...) Handles MyBase.Load
m_lb = _
New System.Drawing.Drawing2D.LinearGradientBrush( _
New Rectangle(0, 0, Me.Panel1.Width, Me.Panel1.Height), _
Color.Red, _
Color.Yellow, _
Drawing.Drawing2D.LinearGradientMode.Horizontal _
)
End Sub

Private Sub Panel1_Paint(...) Handles Panel1.Paint
e.Graphics.FillRectangle(m_lb, 0, 0, Me.Panel1.Width, Me.Panel1.Height)
End Sub

Private Sub Form1_Closing(...) Handles MyBase.Closing
m_lb.Dispose()
End Sub
///
 
D

Dave Veeneman

Danke! (Ich lerne Deutsch). What method would I override to do that in a
custom control derived from the WinForms Panel control? I couldn't find an
OnPaint() for the Panel control.
 
H

Herfried K. Wagner [MVP]

* "Dave Veeneman said:
Danke! (Ich lerne Deutsch). What method would I override to do that in a
custom control derived from the WinForms Panel control? I couldn't find an
OnPaint() for the Panel control.

Mhm... On my machine, there is such a method, but I didn't test if it
is called:

\\\
Public Class Foo
Inherits Panel

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
...
End Sub
End Class
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top