I would like to, if cleanly possible, start a timer after a textbox length has reached a set amount of characters. The timer interval would be set at 'x' amount of seconds and would call my save feature, but I haven't really done anything with timers and not totally sure how to word this event. Could anyone give me an idea as to the approach?

You'll first need to fire an event when a textbox reaches a certain length. You would want to make a sub that Handles MyTextBox.OnTextChanged and checks how many characters are in the textbox.

Then inside that sub, if the number of characters have been reached, you'll enable the timer. Timer1.Enabled = True. Ez pz. How do you make the timer? Drag and drop one onto your form. Right click on it and select properties to set the delay and if it starts enabled or not (you want false). THEN double click on the timer object you dragged onto your form and write the code you want to execute each time.

Edited 4 Years Ago by ZeroZen

You set the timer interval (the time between tick events) via the Interval property. Set it to 1000 for a one second interval. You start the timer by setting Enabled = True.

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

    'this event fires every Timer.Interval milliseconds
    'you could do a file save here

End Sub

Check first the lenght of the characters in the textbox before you execute the timer1_tick event.

Thanks guys. I think I pretty much got it, but do have one question pertaining to the timer. Regardless of the interval it's set at i.e. 5000 milliseconds, does it repeat itself or just stop/dispose?

The timer will continue to fire every Interval milliseconds until you disable it. If you only want it to fire once then you can set Enabled = False in the Tick handler. The next time you set Enabled = True it will fire again after the interval and then disable itself.

This article has been dead for over six months. Start a new discussion instead.