Can a timers 'interval' be Set via a Textbox value edited on a windows form?
I have a timer set at 250000 after I click "start" on my program (i.e. it doesn't start till i tell it to). My question is...if I place Textbox22.Text on my form...Can edit the timer pause in the program on the fly (*aka already compiled*) via that Textbox22.Text & If so how do I do it. Can I just place Textbox22.Text in place of seconds on the actual timer edit window in my visual studio GUI? And just have Textbox22's text already set to 250000? (then later i can change it before starting the program/timer to achieve a different delay before the timer pops off) If not how would I go about making a timer's amount of time editable via the compiled windows form?
I originally did a google search & came up with this msdn forum post http://social.msdn.microsoft.com/For...5-139b0b597546
So i did my homework before posting...its just that post is way over my head & complicated for me. I think that person's needs were not as simple as mine.
Any example is appreciated! And I always make sure to give thanks for all replies * well the ones not making fun of me anyways :blush: *
Thanks Bunches! :duck::duck: GoOse
Re: Can a timers 'interval' be Set via a Textbox value edited on a windows form?
Think about it. If you want to display some text in a TextBox or Label at run time, what do you do? You simply write some code to set the Text property, right? The Interval property of a Timer is just a property, the same a the Text of a TextBox or Label, so you set it the same way.
Re: Can a timers 'interval' be Set via a Textbox value edited on a windows form?
So then using button1_click.... Timer1.Interval = TextBox1.Text
The same way I would do button2_click .... TextBox1.Text = "yo momma"
I'm guessing? Difference is...I was thinking that the static interval set via the IDE would be somehow different. Thanks for making me feel dumb, you got the perfect recipe for that... for me :) lol
Re: Can a timers 'interval' be Set via a Textbox value edited on a windows form?
Here is one way of doing this. Note that I check that what is in the textbox is numeric.
Code:
Private Sub TextBox1_TextChanged(sender As System.Object, _
e As System.EventArgs) Handles TextBox1.TextChanged
'used to set timer interval on the fly
'user input is number of ms followed immediately by #
'e.g. 1000# = 1000 ms
If TextBox1.Text.Trim.EndsWith("#") Then 'does textbox end with #
'yes
Dim s As String = TextBox1.Text.Trim.TrimEnd(New Char() {"#"c}) 'get number part
Dim i As Integer
If Integer.TryParse(s, i) Then 'if it is an integer set timer1.interval
Timer1.Interval = i
TextBox1.Text = ""
Else
Debug.WriteLine("error nan") 'not a number
End If
End If
End Sub