Panel Bordercolor

G

Guest

Hello

I am having an issue with changing the bordercolor of the panel control
I have got to a point where I have created my own control and inherited the Panel control, then in the Overrides Sub OnPaint I draw a rectangle. My code below

The problem I am having is when the new control is resized the border lines are being redrawn over an over again. I guess that makes sense. But how do I clear what was drawn there before

Or I guess the better question would be does anyone else have a better idea on how to change the bordercolor of the panel control

Thanks Jef

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs
MyBase.OnPaint(e

Dim _PenBorder As New Pen(Color.Black, 1
_PenBorder.Color = BorderColo
e.Graphics.DrawRectangle(_PenBorder, 0, 0, MyBase.Width - 1, MyBase.Height - 1
_PenBorder.Dispose(
End Sub
 
M

Michael Maes

Hi Jeff,

This is the code for a Panel I created to Mimic an Office 2003 Panel

I hope this will help you,

Michael

Imports System.ComponentModel

Imports System.Windows.Forms

Imports System.Drawing

<ToolboxBitmap(GetType(UIPanel))> _

Public Class UIPanel

Inherits System.Windows.Forms.Panel

Private Enum ColorScheme

Blue = 0

Gray = 1

Green = 2

End Enum

Dim BorderColor As System.Drawing.Color

Public Sub New()

MyBase.New()

GetBorderColor()

End Sub

Public Overrides Property Site() As ISite

Get

Return MyBase.Site

End Get

Set(ByVal Value As ISite)

MyBase.Site = Value

GetBorderColor()

End Set

End Property

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

MyBase.OnPaint(e)

If Not Me.Width = 0 AndAlso Not Me.Height = 0 Then

Dim g As Graphics = e.Graphics

' Draw Office-Border

Dim p As New Pen(BorderColor, 2)

g.DrawRectangle(p, New Rectangle(0, 0, Me.Width, Me.Height))

' Overlap 3D-Line

p = New Pen(Me.BackColor, 2)

g.DrawRectangle(p, New Rectangle(2, 2, Me.Width - 4, Me.Height - 4))

End If

End Sub

Private Sub GetBorderColor()

' Determine the colorscheme

Dim clr As System.Drawing.Color = System.Drawing.SystemColors.ActiveCaption

Dim s As String

Dim Scheme As ColorScheme = Nothing

If (clr.R = 0 And clr.G = 84 And clr.B = 227) Then

Scheme = ColorScheme.Blue

BorderColor = Color.FromArgb(0, 45, 150)

ElseIf (clr.R = 139 And clr.G = 161 And clr.B = 105) Then

Scheme = ColorScheme.Green

BorderColor = Color.FromArgb(96, 128, 88)

ElseIf (clr.R = 192 And clr.G = 192 And clr.B = 192) Then

Scheme = ColorScheme.Gray

BorderColor = Color.FromArgb(124, 124, 148)

Else 'If IsNothing(Scheme) Then

Scheme = ColorScheme.Blue

End If

End Sub

Private Sub UIPanel_SystemColorsChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.SystemColorsChanged

GetBorderColor()

End Sub

End Class

***************

Jeff S said:
Hello,

I am having an issue with changing the bordercolor of the panel control.
I have got to a point where I have created my own control and inherited
the Panel control, then in the Overrides Sub OnPaint I draw a rectangle. My
code below.
The problem I am having is when the new control is resized the border
lines are being redrawn over an over again. I guess that makes sense. But
how do I clear what was drawn there before.
Or I guess the better question would be does anyone else have a better
idea on how to change the bordercolor of the panel control?
 
K

Ken Tucker [MVP]

Hi,

In addition to the other comments. Invaidate the control in the resize
event.

Ken
------------------
 

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