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
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.
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.