Timer Control - a test program

I want to use a ContainerControl with a Label to display a message to the user. The ContainerControl must be made visible when an event happens (e.g. a try … catch runtime error) and after e.g. 1 second the ContainerControl must be made invisible or disappear controlled by the Timer settings.

I added a Timer control (’Timer1’), a ContainerControl (’ContainerControl11’) and a PushButton (’PushButton1’) to a Window (Window1).

In the Action event of Timer1 I have:

ContainerControl11.lblMessage.Text=""
ContainerControl11.Visible=False

And in the ‘Action’ Event of ‘PushButton1’ I have:

ContainerControl11.lblMessage.Text="Hello"
ContainerControl11.Visible=True
Timer1.Reset

This seems to work. But… I feel uncertain… Is this the correct way to solve my problem?

i would put the timer in the container control, runmode off.
a public method Display with argument message as string in the container control

Public Sub Display(message As String)

Label1.Text = message
Self.Show
Timer1.RunMode = Timer.RunModes.Single
Timer1.Enabled = True

timer action there

Self.Hide
Me.RunMode = Timer.RunModes.Off

the cc in the window by default visible = false

Thank you, Markus. This is a better solution. I had the impression that in my solution the timer was always running and was only reset by Timer1.Reset.

1 Like