En même temps

Résolu
cs_Fyerrblad Messages postés 22 Date d'inscription mercredi 30 mai 2007 Statut Membre Dernière intervention 24 janvier 2008 - 6 nov. 2007 à 14:39
cs_Fyerrblad Messages postés 22 Date d'inscription mercredi 30 mai 2007 Statut Membre Dernière intervention 24 janvier 2008 - 9 nov. 2007 à 14:30
Salut tt le monde.

Je suis en train de créer un programme qui enregistre la position du curseur (X dans ListBox1 et Y dans ListBox2) en cliquant sur Button1.
Button2 sert à arrêter l'enregistrement.
Button3 déclenche deux timers (Timer2 lit le ListBox1 et Timer3 lit le ListBox2).

Tout marche bien, seulement, le mouvement de la souris se fait étape par étape. La souris bouge d'abord horizontalement, puis verticalement. Comment dois-je faire ?

Voici le code :
___________________________________________________________________________________________________
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ListBox1.Items.Add(Cursor.Position.X)
        ListBox2.Items.Add(Cursor.Position.Y)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Stop()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Timer2.Start()
        Timer3.Start()
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        For Each X As Integer In ListBox1.Items
            Cursor.Position = New Point(X, Cursor.Position.Y)
            System.Threading.Thread.Sleep(10)
        Next X
        Timer2.Stop()
    End Sub
    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        For Each Y As Integer In ListBox1.Items
            Cursor.Position = New Point(Cursor.Position.X, Y)
            System.Threading.Thread.Sleep(10)
        Next Y
        Timer3.Stop()
    End Sub
End Class
___________________________________________________________________________________________________

- Fyerrblad -

5 réponses

pneau Messages postés 258 Date d'inscription mercredi 21 avril 2004 Statut Membre Dernière intervention 27 octobre 2010 5
8 nov. 2007 à 09:40
une question bete !
pourquoi 2 timer ?

en fait je pense que lorsque time2 (associé à listbox1) effectue sa boucle, il monopolise le process tant qu'il n'est pas terminé. ce qui fait que ton y ne bouge pas...
puis lorsqu'il a finit, il effectue le code du timer3

il faudrait que tes 2 list box soient lues en meme temps

j'ai fait ce bout de code...
a toi de voir...
et je n'utilise qu'un seul timer

Private
Sub Timer2_Tick(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Timer2.Tick

' For Each X As Integer In ListBox1.Items

' Windows.Forms.Cursor.Position = New Point(X, ListBox2.Items(ListBox1.c()))

' System.Threading.Thread.Sleep(10)

' Next X

Dim nb
As

Long

Dim i
As

Long
nb = ListBox1.Items.Count

For i = 0
To
nb - 1Windows.Forms.Cursor.Position =

New Point(ListBox1.Items.Item(i), ListBox2.Items.Item(i))System.Threading.Thread.Sleep(10)

Next
Timer2.Stop()

End
Sub

Pat
3
cs_Fyerrblad Messages postés 22 Date d'inscription mercredi 30 mai 2007 Statut Membre Dernière intervention 24 janvier 2008
6 nov. 2007 à 15:37
Personne ?

- Fyerrblad -
0
pneau Messages postés 258 Date d'inscription mercredi 21 avril 2004 Statut Membre Dernière intervention 27 octobre 2010 5
7 nov. 2007 à 10:49
salut
c'est quoi ton probleme exactement ?
sois plus précis svp sur le fonctionnement attendu de ton dev

Pat
0
cs_Fyerrblad Messages postés 22 Date d'inscription mercredi 30 mai 2007 Statut Membre Dernière intervention 24 janvier 2008
7 nov. 2007 à 20:58
Salut.

Bon, en fait, quand je clique sur Button3, la souris fait le mouvement horizontal (Position X de la souris = ListBox1)
puis quand le mouvement horizontal est terminé, c'est seulement maintenant que le mouvement vertical (Position Y de la souris = ListBox2) commence.

Exemple :

J'enregistre le mouvement :

ListBox1/ListBox2
12         /21
13         /65
15         /20
19         /18
20         /14

alors ça fait d'abord

Mouvement X : 12 - 13 - 15 - 19 - 20
puis APRES
Mouvement Y : 21 - 65 - 20 - 18 - 14

- Fyerrblad -
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_Fyerrblad Messages postés 22 Date d'inscription mercredi 30 mai 2007 Statut Membre Dernière intervention 24 janvier 2008
9 nov. 2007 à 14:30
Merci Pat !

Ca marche et c'est plus simple !

Merci encore ! =P

- Fyerrblad -
0
Rejoignez-nous