Imports System.ComponentModel
Imports System.Drawing.Drawing2D
Public Class GradientBackground
Inherits System.Windows.Forms.Control
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'GradientBackground
'
Me.Name = "GradientBackground"
Me.Size = New System.Drawing.Size(632, 24)
End Sub
#End Region
'The start color property
Dim m_StartColor As Color = Color.CornflowerBlue
<Description("The start color for the gradient")> _
Property StartColor() As Color
Get
Return m_StartColor
End Get
Set(ByVal Value As Color)
m_StartColor = Value
'Redraw the control when this property changes
Me.Invalidate()
End Set
End Property
Sub ResetStartColor()
m_StartColor = Color.CornflowerBlue
End Sub
Function ShouldSerializeStartColor() As Boolean
Return Not m_StartColor.Equals(Color.CornflowerBlue)
End Function
'The end color property
Dim m_EndColor As Color = Color.Goldenrod
<Description("The end color for the gradient")> _
Property EndColor() As Color
Get
Return m_EndColor
End Get
Set(ByVal Value As Color)
m_EndColor = Value
'Redraw the control if this value changes
Me.Invalidate()
End Set
End Property
Sub ResetEndColor()
m_EndColor = Color.Goldenrod
End Sub
Function ShouldSerializeEndColor() As Boolean
Return Not m_EndColor.Equals(Color.Goldenrod)
End Function
'The gradient mode property
Dim m_GradientMode As LinearGradientMode = _
LinearGradientMode.ForwardDiagonal
<Description("The gradient mode"), _
DefaultValue(LinearGradientMode.ForwardDiagonal)> _
Property GradientMode() As LinearGradientMode
Get
Return m_GradientMode
End Get
Set(ByVal Value As LinearGradientMode)
m_GradientMode = Value
'Redraw when changed
Me.Invalidate()
End Set
End Property
'Render the control background
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
'Create a gradient brush as a large client area with specified
'start/end color and gradient mode.
Dim br As New LinearGradientBrush(Me.ClientRectangle, _
m_StartColor, m_EndColor, m_GradientMode)
'paint the rectangle
e.Graphics.FillRectangle(br, Me.ClientRectangle)
'destroy the brush
br.Dispose()
'let the base control do the work...
MyBase.OnPaint(e)
End Sub
Private Sub GradientBackground_Resize(ByVal sender As Object, _
ByVal e As EventArgs)
Me.Invalidate()
End Sub