Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.ComponentModel
Public Class zsPanelHeader
Inherits Panel
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Private components As System.ComponentModel.IContainer
Public Enum Curve As Integer
Triangle
SigmaBell
End Enum
Public Enum GradientType As Integer
SideToSide
InOut
End Enum
Private Sub MyGradient(ByVal gr As Graphics)
If Me.Width = 0 Or Me.Height = 0 Then Exit Sub
Dim zsRectangulo As Rectangle
' Linear Gradient
If zsGradientType = GradientType.SideToSide Then
If MinHeight > 0 Then 'Header
zsRectangulo = New Rectangle(0, 0, Me.Width, zsMinHeight)
Dim zsbrocha As New LinearGradientBrush(zsRectangulo, _
ColorHeader1, ColorHeader2, Gradient)
If CurveGradient = Curve.SigmaBell Then
zsbrocha.SetSigmaBellShape(Blend)
Else
zsbrocha.SetBlendTriangularShape(Blend)
End If
gr.FillRectangle(zsbrocha, zsRectangulo)
zsbrocha.Dispose()
End If
If Me.Height > zsMinHeight Then ' Body
zsRectangulo = New Rectangle(0, MinHeight, Me.Width, _
Me.Height - zsMinHeight)
Dim zsbrocha As New LinearGradientBrush(zsRectangulo, _
Color1, Color2, Gradient)
If CurveGradient = Curve.SigmaBell Then
zsbrocha.SetSigmaBellShape(Blend)
Else
zsbrocha.SetBlendTriangularShape(Blend)
End If
gr.FillRectangle(zsbrocha, zsRectangulo)
zsbrocha.Dispose()
End If
' In-Out Gradient
Else
If MinHeight > 0 Then 'Header
Dim pnt() As Point = {New Point(0, 0), New Point(Me.Width, 0), _
New Point(Me.Width, zsMinHeight), New Point(0, zsMinHeight)}
Dim zsbrocha As New PathGradientBrush(pnt)
zsbrocha.CenterColor = ColorHeader1
zsbrocha.SurroundColors = New Color() {ColorHeader2}
If CurveGradient = Curve.SigmaBell Then
zsbrocha.SetSigmaBellShape(Blend)
Else
zsbrocha.SetBlendTriangularShape(Blend)
End If
gr.FillPolygon(zsbrocha, pnt)
zsbrocha.Dispose()
End If
If Me.Height > zsMinHeight Then 'Body
Dim pnt() As Point = {New Point(0, zsMinHeight), _
New Point(Me.Width, zsMinHeight), _
New Point(Me.Width, zsMaxHeight), New Point(0, zsMaxHeight)}
Dim zsbrocha As New PathGradientBrush(pnt)
zsbrocha.CenterColor = Color1
zsbrocha.SurroundColors = New Color() {Color2}
If CurveGradient = Curve.SigmaBell Then
zsbrocha.SetSigmaBellShape(Blend)
Else
zsbrocha.SetBlendTriangularShape(Blend)
End If
gr.FillPolygon(zsbrocha, pnt)
zsbrocha.Dispose()
End If
End If
zsRectangulo = Nothing
gr.Dispose()
End Sub
Dim zsColor1 As Color = Color.RoyalBlue
<Description("First Gradient Color"), Category("Gradient")> _
Public Property Color1() As Color
Get
Color1 = zsColor1
End Get
Set(ByVal value As Color)
zsColor1 = value
Me.Refresh()
End Set
End Property
Dim zsColor2 As Color = Color.LightSkyBlue
<Description("Second Gradient Color"), Category("Gradient")> _
Public Property Color2() As Color
Get
Color2 = zsColor2
End Get
Set(ByVal value As Color)
zsColor2 = value
Me.Refresh()
End Set
End Property
Dim zsColorHeader1 As Color = Color.Maroon
<Description("First Header Gradient Color"), Category("Gradient")> _
Public Property ColorHeader1() As Color
Get
ColorHeader1 = zsColorHeader1
End Get
Set(ByVal value As Color)
zsColorHeader1 = value
Me.Refresh()
End Set
End Property
Dim zsColorHeader2 As Color = Color.Gold
<Description("Second Header Gradient Color"), Category("Gradient")> _
Public Property ColorHeader2() As Color
Get
ColorHeader2 = zsColorHeader2
End Get
Set(ByVal value As Color)
zsColorHeader2 = value
Me.Refresh()
End Set
End Property
Dim zsGradientMode As LinearGradientMode = LinearGradientMode.Vertical
<Description("Gradient Mode"), Category("Gradient")> _
Public Property Gradient() As LinearGradientMode
Get
Gradient = zsGradientMode
End Get
Set(ByVal value As LinearGradientMode)
zsGradientMode = value
Me.Refresh()
End Set
End Property
Dim zsBlend As Single = 0.5
<Description("Single number [0 to 1] indicating blend center position"), _
Category("Gradient")> _
Public Property Blend() As Single
Get
Blend = zsBlend
End Get
Set(ByVal value As Single)
If value > 1 Then value = 1
If value < 0 Then value = 0
zsBlend = value
Me.Refresh()
End Set
End Property
Dim zsCurve As Curve = Curve.Triangle
<Description("Curve"), Category("Gradient")> _
Public Property CurveGradient() As Curve
Get
CurveGradient = zsCurve
End Get
Set(ByVal value As Curve)
zsCurve = value
Me.Refresh()
End Set
End Property
Dim zsGradientType As GradientType = GradientType.SideToSide
<Description("Gradient direction"), Category("Gradient")> _
Public Property Direction() As GradientType
Get
Direction = zsGradientType
End Get
Set(ByVal value As GradientType)
zsGradientType = value
Me.Refresh()
End Set
End Property
Dim zsMinHeight As Integer = 30
<Description("Height of collapsed panel"), Category("Collapse")> _
Public Property MinHeight() As Integer
Get
MinHeight = zsMinHeight
End Get
Set(ByVal value As Integer)
zsMinHeight = value
End Set
End Property
Dim zsMaxHeight As Integer = 100
<Description("Height of expanded panel"), Category("Collapse")> _
Public Property MaxHeight() As Integer
Get
MaxHeight = zsMaxHeight
End Get
Set(ByVal value As Integer)
zsMaxHeight = value
End Set
End Property
Dim zsSpeed As Integer = 10
<Description("Collapsing/Expanding Speed"), Category("Collapse")> _
Public Property Speed() As Integer
Get
Speed = zsSpeed
End Get
Set(ByVal value As Integer)
If value < 1 Then value = 1
If value > zsMaxHeight - zsMinHeight Then value = zsMaxHeight - zsMinHeight
zsSpeed = value
End Set
End Property
Dim zsCollapsed As Boolean
Dim inc As Integer = 1
<Description("Indicates whether the panel is collapsed"), Category("Collapse")> _
Public Property Collapsed() As Boolean
Get
Collapsed = zsCollapsed
End Get
Set(ByVal value As Boolean)
If value <> zsCollapsed Then
zsCollapsed = value
StartAction()
End If
End Set
End Property
Private Sub Gradient_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
MyGradient(e.Graphics)
End Sub
Public Sub StartAction()
If Me.Height <= zsMinHeight Then inc = 1 Else inc = -1
Timer1.Start()
Resizing = True
RaiseEvent ActionStarted()
End Sub
Public Event ActionStarted()
Public Event ActionStopped()
Public Event ActionTick()
Public Resizing As Boolean = False
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Timer1.Tick
If inc < 0 And Me.Height <= zsMinHeight Then
Timer1.Stop()
Me.Height = zsMinHeight
RaiseEvent ActionStopped()
Resizing = False
ElseIf inc > 0 And Me.Height >= zsMaxHeight Then
Timer1.Stop()
Me.Height = zsMaxHeight
RaiseEvent ActionStopped()
Resizing = False
Else
Me.Height += inc * zsSpeed
RaiseEvent ActionTick()
End If
End Sub
Public Sub New() ' CONSTRUCTOR
Me.components = New System.ComponentModel.Container
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.Timer1.Interval = 10
Me.Enabled = False
Me.SuspendLayout()
Me.ResumeLayout(False)
End Sub
Private Sub zsPanel_Resize(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Resize
If Me.DesignMode And Not Resizing Then
If zsCollapsed Then
zsMinHeight = Me.Height
If Me.Height > zsMaxHeight Then Me.Height = zsMaxHeight
Else
zsMaxHeight = Me.Height
If Me.Height < zsMinHeight Then Me.Height = zsMinHeight
End If
End If
Me.Refresh()
End Sub
End Class