Results 1 to 11 of 11

Thread: [RESOLVED] Question on implementing/using control extensions

Threaded View

  1. #5
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Question on implementing/using control extensions

    Yes,

    You start a new class and just under the class name you use the keywords
    'Inherits Label'.
    Whatever properties, procedures and events you add to it extends what it can do.

    Since you are not overriding any of the label's features the syntax should be straight forward.

    Code:
    Public Class TimedLabel
      Inherits Label
    
      Private WithEvents LabelTimer As New Timer
    
      Public Property Interval() As Integer
        Get
          Return LabelTimer.Interval
        End Get
        Set(value As Integer)
          LabelTimer.Interval = value
        End Set
      End Property
    
      Public Sub Start()
        LabelTimer.Start()
      End Sub
    
      Public Sub [Stop]()
        LabelTimer.Stop()
      End Sub
    
      Private Sub LabelTimer_Tick(sender As System.Object, e As System.EventArgs) Handles LabelTimer.Tick
        LabelTimer.Stop()
        Me.Text = ""
      End Sub
    End Class
    
    ' In use
    
    Public Class Form1
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        With TimedLabel1
          .Text = "This is Message to be shown for five seconds"
          .Interval = 5000
          .Start()
        End With
      End Sub
    End Class
    Last edited by Gruff; Jul 27th, 2014 at 09:39 AM.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width