|
-
May 22nd, 2006, 10:32 AM
#1
Thread Starter
Lively Member
Can a timer be started as a thread and execute with KeyDown?
Hi,
Can a timer tick event be started as a seperate thread and be executed concurrently with the KeyDown event?
When I press the Up arrow key, a picturebox1 has to go up and down the form vertically (jumping). At the same time, I would like the timer tick event to continue to move another picturebox2 from right to left on the form by 1 pixel for each tick event.
Initially, these 2 events cant be dealt with concurrently by vb, so I used the Application.DoEvent() method recommended by some replies I have received in the forums.
It works partially. Pictuerbox2 can move while the up arrow key is being pressed but it moves jerkily. Besides, when the arrow key is being released, picturebox1 continues to jump when it is supposed to stop.
So can I start a new thread which can execute when these 2 events occur?
If so, could you provide a simple example?
-
May 22nd, 2006, 10:51 AM
#2
Re: Can a timer be started as a thread and execute with KeyDown?
 Originally Posted by LiLo
Hi,
Can a timer tick event be started as a seperate thread and be executed concurrently with the KeyDown event?
When I press the Up arrow key, a picturebox1 has to go up and down the form vertically (jumping). At the same time, I would like the timer tick event to continue to move another picturebox2 from right to left on the form by 1 pixel for each tick event.
Initially, these 2 events cant be dealt with concurrently by vb, so I used the Application.DoEvent() method recommended by some replies I have received in the forums.
It works partially. Pictuerbox2 can move while the up arrow key is being pressed but it moves jerkily. Besides, when the arrow key is being released, picturebox1 continues to jump when it is supposed to stop.
So can I start a new thread which can execute when these 2 events occur?
If so, could you provide a simple example?
Hi,
You can use the KeyDown event and execute then your code;
VB Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Up Then
' execute here your code to change the location of your TextBox
else
Timer1.Enable = False
End If
End Sub
Hope it helps,
sparrow1
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
|