|
-
Nov 23rd, 2006, 01:33 AM
#1
Thread Starter
Member
[2005] Timer Control
Hello, i've just got a quick question to do with the Timer Control.
I haven't been able to get it to work for a while.
I just don't know how to use it, i've looked at the Microsoft help website but that didn't help me. could anyone explain how to use it and code it. Or could someone add a timer to this code, so that say 1 letter appears every 2 seconds.
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim text As System.Diagnostics.Process
Text = System.Diagnostics.Process.Start("C:\WINDOWS\Notepad.exe")
text.WaitForInputIdle()
AppActivate(text.Id)
SendKeys.Send("Hello, this is just a test .")
End Sub
Thanks
-
Nov 23rd, 2006, 02:52 AM
#2
Re: [2005] Timer Control
Set the Timer's Interval to 2000 (milliseconds).
Set its Enabled property to True or call its Start method when you want it to start.
You will need to store your string in a class level variable and also store a number that indicates the index of the next character.
In the Timer's Tick event handler you use the character at the current index and then increment the index.
When all the characters have been sent you set the Timer's Enabled property to False or call its Stop method.
Having said all that, using SendKeys like that is not a very good idea because if a different application becomes active the key strokes will be sent to it instead.
By the way, Timer's are not controls. They are components.
-
Nov 23rd, 2006, 06:07 AM
#3
Thread Starter
Member
Re: [2005] Timer Control
Thanks for the reply but i didn't understand alot of what you said. Would you be able to post a code example of using a timer in a simple application?
If sendkeys isn't the best method to use would you be able to list another method?
-
Nov 23rd, 2006, 06:21 AM
#4
Lively Member
Re: [2005] Timer Control
VB Code:
Private Idx as integer = 0
Private strToDisplay as string = "Hello, this is just a test ."
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim text As System.Diagnostics.Process
Text = System.Diagnostics.Process.Start("C:\WINDOWS\Notepad.exe")
text.WaitForInputIdle()
AppActivate(text.Id)
Idx = 0
Me.Timer1.Interval = 2000
Me.Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
SendKeys.Send(strToDisplay.substring(Idx,1)
SendKeys.Flush()
idx = idx + 1
if idx > strToDisplay.Length then
Me.Timer1.Stop()
End If
End Sub
-
Nov 23rd, 2006, 06:27 AM
#5
Thread Starter
Member
Re: [2005] Timer Control
Thanks for the code lingsn.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|