Panel Bordercolor
(Thursday, January 27, 2005)
Found the following interesting discussion in the Newsgroups:
Panel Bordercolor by:Anonymous
| 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 Jeff
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e)
Dim _PenBorder As New Pen(Color.Black, 1) _PenBorder.Color = BorderColor e.Graphics.DrawRectangle(_PenBorder, 0, 0, MyBase.Width - 1, MyBase.Height - 1) _PenBorder.Dispose() End Sub
| | | Reply: by: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
| | | Reply: by:Ken Tucker [MVP]
| | | Hi,
In addition to the other comments. Invaidate the control in the resize event.
Ken -- Outgoing mail is certified Virus Free. Checked by AVG Anti-Virus (http://www.grisoft.com). Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004
|
Posted by Xander Zelders

|
0 Comments:
Post a Comment
<< Home