Results 1 to 10 of 10

Thread: Getting a Label control's text to update

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    158

    Question Getting a Label control's text to update

    I am working on a small application that includes several Label controls and I would like to update the text in these controls. Thus far, the only things that works is to delete the control, then recreate it. I am certain that there is a better way, but I have not yet found it.

    Following is a simplified version of my code that shows what I have tried that doesn't work.
    Code:
    Public Class frmMyTime
        Dim gTime As String
        Dim lblTime As Label
    
        Private Sub frmMyTime_Load(sender As Object, e As EventArgs) Handles Me.Load
            lblTime = New label
            Me.Controls.Add(lblTime)
        End Sub
    
        Private Sub frmMyTime_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            lblTime.Text = gTime
        End Sub
    
        Private ub GetTime()
            gTime = DateTime.Now.ToString("HH:mm:ss")
            Me.Refresh()
        End Sub
    
        Public Sub frmMyTime_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
            GetTime()
        End Sub
    End Class
    Can you please tell me what to change to make this work. Thanks!
    Last edited by groston; Jun 29th, 2022 at 09:52 AM.

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