Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo  
 
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



 
Previous Posts
    - Can a Property be an array?
    - Can't run my exe from a network share!
    - OT: I'm comming back
    - How to adress an Embedded Crystal Report from VB c...
    - How to run only once
    - OutOfMemoryException
    - How to transfer values bewteen Integer and UInt32 ...
    - How to transfer values between Integer and UInt32 ...
    - How to set file persmissions with WMI using a UNC ...
    - Week date

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland