Imports System.Drawing.Drawing2D

Public Class AdvancedLabel
    '        label 
    '   
    Inherits Label
    'enum  styles
    Enum tStyles
        No_Style
        Style_1
        Style_2
        Style_3
    End Enum
    'enum      
    '   Label or ToolTip
    Enum lType
        Label
        ToolTip
    End Enum
    '     
    Dim St As tStyles
    Dim _Active As Boolean
    Dim _ToolTipTxt As String
    Dim _TimeToDispear As Integer
    Dim Control As Object
    Dim _Style1frstColor As Color
    Dim _Style1scndColor As Color
    Dim _Style3CenterColor As Color
    Dim ChoosenType As lType
    '        HatchBrush
    Dim _PenStyle2 As HatchStyle
    Dim _Style1GradientMode As LinearGradientMode
    Dim _Picture As String
    Dim _ShadowLetters As Boolean
    Dim _ShadowLabel As Boolean

#Region " Code gnr par le Concepteur Windows Form "

    Public Sub New()
        MyBase.New()

        'Cet appel est requis par le Concepteur Windows Form.

        InitializeComponent()
        'ici on initialize les proprits 
        'Me.BorderStyle = BorderStyle.FixedSingle
        Style1SecondColor = Color.Blue
        Style1FirstColor = Color.White
        Style3CenterColor = Color.White
        Active = True
        TimeToDispear = 4
        Text = Name
        ShadowLetters = False
        'Ajoutez une initialisation quelconque aprs l'appel InitializeComponent()

    End Sub

    'La mthode substitue Dispose du UserControl1 pour nettoyer la liste des composants.
    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

    'Requis par le Concepteur Windows Form
    Private components As System.ComponentModel.IContainer

    'REMARQUE: la procdure suivante est requise par le Concepteur Windows Form
    'Elle peut tre modifie en utilisant le Concepteur Windows Form.  
    'Ne la modifiez pas en utilisant l'diteur de code.
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        '
        'Timer1
        '
        Me.Timer1.Interval = 1000
        '
        'AdvancedLabel
        '

    End Sub

#End Region
    '               
    Property ShadowLetters() As Boolean

        Get
            ShadowLetters = _ShadowLetters
        End Get
        Set(ByVal Value As Boolean)
            _ShadowLetters = Value
        End Set

    End Property
    
    '           
    Property Style3CenterColor() As Color

        Get
            Style3CenterColor = _Style3CenterColor
        End Get
        Set(ByVal Value As Color)
            _Style3CenterColor = Value
        End Set

    End Property
    '         
    Property Style1GradientMode() As LinearGradientMode

        Get
            Style1GradientMode = _Style1GradientMode
        End Get
        Set(ByVal Value As LinearGradientMode)
            _Style1GradientMode = Value
        End Set

    End Property
    '          50  
    Property StyleOfStyle2() As HatchStyle

        Get
            StyleOfStyle2 = _PenStyle2
        End Get
        Set(ByVal Value As HatchStyle)
            _PenStyle2 = Value
        End Set

    End Property
    '              
    Property Type() As lType

        Get
            Type = ChoosenType
        End Get
        Set(ByVal Value As lType)
            ChoosenType = Value
        End Set

    End Property
    '    False
    '     
    Property Active() As Boolean

        Get
            Active = _Active
        End Get
        Set(ByVal Value As Boolean)
            _Active = Value
        End Set

    End Property
    '                
    Property Style1FirstColor() As Color

        Get
            Style1FirstColor = _Style1frstColor
        End Get
        Set(ByVal Value As Color)
            _Style1frstColor = Value
        End Set

    End Property
    '   
    Property Style1SecondColor() As Color

        Get
            Style1SecondColor = _Style1scndColor
        End Get
        Set(ByVal Value As Color)
            _Style1scndColor = Value
        End Set

    End Property
    '    )(     
    '   ToolTip
    Property TimeToDispear() As Integer

        Get
            If TimeToDispear = 0 Then
                TimeToDispear = _TimeToDispear
            End If
        End Get
        Set(ByVal Value As Integer)
            _TimeToDispear = Value
        End Set

    End Property
    '              
    '        
    Property Styles() As tStyles

        Get
            Styles = St
        End Get
        Set(ByVal Value As tStyles)
            St = Value
        End Set

    End Property

    '              
    '             
    '               ToolTip
    '          5   6    
    '     ToolTip
    '           

    Public Sub AdvancedLabel(ByVal Container As Object, Optional ByVal AStyle As tStyles = tStyles.No_Style, Optional ByVal TxtToolTip As String = "", Optional ByVal Time As Integer = 0, Optional ByVal sStyle2 As HatchStyle = HatchStyle.BackwardDiagonal, Optional ByVal ModeGradient As LinearGradientMode = LinearGradientMode.BackwardDiagonal)
        'Container = Me

        Control = Container
        '  Active=false we exit from the sub else we continue

        If _Active = False Then Exit Sub
        If Type = lType.ToolTip Then
            If Time = 0 Then
                Timer1.Enabled = True
            Else
                TimeToDispear = Time
                Timer1.Enabled = True
            End If
        End If
        '                    
        '  
        If TxtToolTip <> "" Then
            Text = TxtToolTip
        End If
        If AStyle = 0 Then
            AStyle = Styles
        End If
        If sStyle2 = HatchStyle.BackwardDiagonal Then
            sStyle2 = StyleOfStyle2
        Else
            StyleOfStyle2 = sStyle2
        End If
        Style1GradientMode = ModeGradient
        Me.Visible = True
        Select Case AStyle
            Case tStyles.No_Style
                NoStyle()
            Case tStyles.Style_1
                Style1()
            Case tStyles.Style_2
                Style2()
            Case tStyles.Style_3
                Style3()
        End Select

    End Sub
    '/// *-*-*-*-*-*-*-*STYLE-1-*-*-*-*-*-*-*\\\'

    Private Sub Style1()
        '    SizeF      
        Dim Size As SizeF
        '   
        Dim Point As Point
        '   
        Me.BringToFront()
        '       
        Point = Control.PointToClient(New Point(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y))
        '  
        Size = Control.CreateGraphics.MeasureString(Text, Me.Font)
        '     ToolTip
        '            
        If Type = lType.ToolTip Then
            Me.Top = Point.Y + 1 : Me.Left = Point.X
        End If
        '          
        Me.Width = Size.Width + 4 : Me.Height = Size.Height + 5
        '   
        Dim Rect As New Rectangle(0, 0, Me.Width, Me.Height)
        '               
        '         Style1FirstColor Style1SecondColor
        Dim NewBru As New LinearGradientBrush(Rect, Style1FirstColor, Style1SecondColor, Style1GradientMode)
        '                    ForeColor
        ' :      
        Dim Penn As New SolidBrush(Me.ForeColor)
        Application.DoEvents()
        '       
        Me.CreateGraphics.FillRectangle(NewBru, Rect)
        '             
        If ShadowLetters = True Then
            Me.CreateGraphics.DrawString(Text, Me.Font, New SolidBrush(Color.Gray), Rect.X + 3, Rect.Y + 3)
        End If
        '  
        Me.CreateGraphics.DrawString(Text, Me.Font, Penn, Rect.X, Rect.Y)
        ' -  -  
        NewBru.Dispose()
        Penn.Dispose()

    End Sub
    '///-*-*-*-*-*-*-*-*-* NOSTYLE -*-*-*-*-*-*-*-*-*-*-*\\\'
    '        
    Private Sub NoStyle()
        '     
        Me.Refresh()
        Dim Size As SizeF
        Dim Point As Point
        Me.BringToFront()
        Point = Control.PointToClient(New Point(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y))
        Size = Control.CreateGraphics.MeasureString(Text, Me.Font)
        If Type = lType.ToolTip Then
            Me.Top = Point.Y + 1 : Me.Left = Point.X
        End If
        Me.Width = Size.Width + 4 : Me.Height = Size.Height

    End Sub
    '/// -*-*-*-*-*-*-*-*-*-*-* STYLE2 *-*-*-*-*-*-*-*-*-*-* \\\'
    Private Sub Style2()

        Dim Size As SizeF
        Dim Point As Point
        Me.BringToFront()
        Point = Control.PointToClient(New Point(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y))
        Size = Control.CreateGraphics.MeasureString(Text, Me.Font)
        If Type = lType.ToolTip Then
            Me.Top = Point.Y + 1 : Me.Left = Point.X
        End If
        Me.Width = Size.Width + 4 : Me.Height = Size.Height
        Dim Rect As New Rectangle(0, 0, Me.Width, Me.Height)
        Dim ScnRect As New Rectangle(3, 3, Me.Width, Me.Height)
        '         1             
        '     StyleOfStyle2
        '      50 
        Dim NewBru As New HatchBrush(StyleOfStyle2, Color.FromArgb(50, 0, 0, 255))
        Dim Penn As New SolidBrush(Me.ForeColor)
        Application.DoEvents()
        Me.CreateGraphics.FillRectangle(NewBru, Rect)
        If ShadowLetters = True Then
            Me.CreateGraphics.DrawString(Text, Me.Font, New SolidBrush(Color.Gray), ScnRect.X, ScnRect.Y)
        End If
        Me.CreateGraphics.DrawString(Text, Me.Font, Penn, Rect.X, Rect.Y)
        NewBru.Dispose()
        Penn.Dispose()

    End Sub

    '///-*-*-*-*-*-*-*-*-*-*-*-*-*- STYLE3 -*-*-*-*-*-*-*-*-*-*\\\'
    Private Sub Style3()

        Dim Size As SizeF
        Dim Point As Point
        Me.BringToFront()
        Point = Control.PointToClient(New Point(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y))
        Size = Control.CreateGraphics.MeasureString(Text, Me.Font)
        If Type = lType.ToolTip Then
            Me.Top = Point.Y + 0.5 : Me.Left = Point.X
        End If
        Me.Width = Size.Width + 4 : Me.Height = Size.Height
        Dim Rect As New Rectangle(0, 0, Me.Width, Me.Height)
        Dim ScnRect As New Rectangle(3, 3, Me.Width, Me.Height)

        Dim PathG As New GraphicsPath
        '     
        PathG.AddRectangle(Rect)
        Dim NewBru As New PathGradientBrush(PathG)
        Dim Penn As New SolidBrush(Me.ForeColor)
        '          
        '           
        '  DLL
        '  
        Dim SColors() As Color = {Color.AliceBlue, Color.CadetBlue, Color.Cyan, Color.LightBlue}
        '      
        NewBru.CenterColor = Style3CenterColor
        NewBru.SurroundColors = SColors
        Application.DoEvents()
        Me.CreateGraphics.FillPath(NewBru, PathG)
        If ShadowLetters = True Then
            Me.CreateGraphics.DrawString(Text, Me.Font, New SolidBrush(Color.Gray), ScnRect.X, ScnRect.Y)
        End If
        Me.CreateGraphics.DrawString(Text, Me.Font, Penn, Rect.X, Rect.Y)
        NewBru.Dispose()
        Penn.Dispose()

    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        '    
        TimeToDispear -= 1
        If TimeToDispear <= 0 Then
            TimeToDispear = 4
            Timer1.Enabled = False
            Me.Visible = False
        End If

    End Sub

    Private Sub AdvancedLabel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
        '     ToolTip
        '    
        If Type = lType.ToolTip Then Me.Visible = False

    End Sub

End Class
