Results 1 to 3 of 3

Thread: Question about user defined control

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Question about user defined control

    I created the following control and added it to a form in the form design. I was curious about a couple of things. First, even in the IDE it is running and updating the time and date. Is this normal. Secondly, is this a normal way to add date/time to a user defined control?

    HTML Code:
    Public Class MyStatusbar
        Inherits Windows.Forms.StatusStrip
        Private sslTime As New ToolStripStatusLabel
        Private sslDate As New ToolStripStatusLabel
        Private sslStatus As New ToolStripStatusLabel
        Private WithEvents ssTimer As New Timer
    
        Public Sub New()
            MyBase.New()
            
            Me.Items.AddRange(New System.Windows.Forms.ToolStripItem() {sslTime, sslDate, sslStatus})
    
            sslTime.AutoSize = False
            sslTime.Name = "sslTime"
            sslTime.Size = New System.Drawing.Size(120, 18)
            sslTime.Text = Now.ToLongTimeString
    
            sslDate.AutoSize = False
            sslDate.Name = "sslDate"
            sslDate.Size = New System.Drawing.Size(120, 18)
            sslDate.Text = Now.ToShortDateString
    
            sslStatus.AutoSize = True
            sslStatus.TextAlign = ContentAlignment.MiddleCenter
            sslStatus.Name = "sslStatus"
            sslStatus.Text = "No status updates available"
    
            ssTimer.Enabled = True
            ssTimer.Interval = 900
    
        End Sub
    
        Private Sub UpdateTime(ByVal sender As Object, ByVal e As System.EventArgs) Handles ssTimer.Tick
            sslDate.Text = Now.ToShortDateString
            sslTime.Text = Now.ToLongTimeString
        End Sub
    
        Public Sub UpdateStatus(ByVal msg As String, ByVal fnt As Font)
            Dim sze As Single = fnt.Size
            If sze > sslStatus.Height Then
                sze = sslStatus.Height
            Else
                sze = fnt.SizeInPoints
            End If
            sslStatus.Text = msg
            sslStatus.Font = New Drawing.Font(fnt.SystemFontName, fnt.SizeInPoints, fnt.Style)
        End Sub
    End Class
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Question about user defined control

    You might like to check out this:

    http://www.vbforums.com/showthread.php?t=418118

    It's a custom status label that you can add to any StatusStrip. I think it provides a little more flexibility. You can then add an instance to a custom StatusStrip if you want to use it in multiple forms. I would think that it would only be your main form that would need it though, so a custom class would not be necessary.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Re: Question about user defined control

    Thanks! I've downloaded this code and will take a look and try to understand it. Hope you don't mind if I post questions about it.
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

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