Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - come far muovere un oggetto in una form
Forum - Visual Basic 6 - come far muovere un oggetto in una form

Pagine: [ 1 2 ] Precedente | Prossimo
Avatar
capokkia89 (Normal User)
Newbie


Messaggi: 8
Iscritto: 25/01/2011

Segnala al moderatore
Postato alle 12:53
Martedì, 25/01/2011
ho un piccolo problema sto facendo un programmino semplice .. dovrei simulare un sitema simplex ,half duplex e full duplex .
ecco il codice
[Dim x As Long
Dim y As Long
Dim m As Long
Dim n As Long

Dim nState As Integer
Dim nstate1 As Integer


Private Sub Command1_Click()
    x = img1.Left
    y = img1.Top
    Timer1.Interval = 500
    Timer1.Enabled = True
End Sub

Private Sub Command2_Click()
    Timer1.Enabled = False
End Sub


Private Sub Timer1_Timer()
    nState = nState + 1
    If nState = 1 Then
        img1.Left = img2.Left
        img1.Top = img2.Top
    ElseIf nState = 2 Then
        img1.Left = img3.Left
        img1.Top = img3.Top
    ElseIf nState = 3 Then
        img1.Left = img4.Left
        img1.Top = img4.Top
    ElseIf nState = 4 Then
        img1.Left = img5.Left
        img1.Top = img5.Top
    ElseIf nState = 5 Then
        img1.Left = img6.Left
        img1.Top = img6.Top
    ElseIf nState = 6 Then
        img1.Left = img7.Left
        img1.Top = img7.Top
    ElseIf nState = 7 Then
        img1.Left = img8.Left
        img1.Top = img8.Top
    ElseIf nState = 8 Then
        img1.Left = img9.Left
        img1.Top = img9.Top
    ElseIf nState = 9 Then
        img1.Left = img10.Left
        img1.Top = img10.Top
    ElseIf nState = 10 Then
        img1.Left = img11.Left
        img1.Top = img11.Top
    ElseIf nState = 11 Then
        img1.Left = img12.Left
        img1.Top = img12.Top
    Else
        img1.Left = x
        img1.Top = y
        nState = 0
        
        
    
    End If
End Sub

Private Sub Command3_Click()
    m = img13.Left
    n = img13.Top
    Timer2.Interval = 1000
    Timer2.Enabled = True
End Sub

Private Sub Command4_Click()
    Timer2.Enabled = False
End Sub



Private Sub Timer2_Timer()
    nstate1 = nstate1 + 1
    If nstate1 = 13 Then
        img13.Left = img14.Left
        img13.Top = img14.Top
    ElseIf nstate1 = 14 Then
        img13.Left = img15.Left
        img13.Top = img15.Top
    ElseIf nstate1 = 15 Then
        img13.Left = img16.Left
        img13.Top = img16.Top
    ElseIf nstate1 = 16 Then
        img13.Left = img17.Left
        img13.Top = img17.Top
    ElseIf nstate1 = 17 Then
        img13.Left = img18.Left
        img13.Top = img18.Top
    ElseIf nstate1 = 18 Then
        img13.Left = img19.Left
        img13.Top = img19.Top
    ElseIf nstate1 = 19 Then
        img13.Left = img20.Left
        img13.Top = img20.Top
    ElseIf nstate1 = 20 Then
        img13.Left = img21.Left
        img13.Top = img21.Top
    ElseIf nstate1 = 21 Then
        img13.Left = img22.Left
        img13.Top = img22.Top
    ElseIf nstate1 = 22 Then
        img13.Left = img23.Left
        img13.Top = img23.Top
    ElseIf nstate1 = 23 Then
        img13.Left = img24.Left
        img13.Top = img24.Top
    ElseIf nstate1 = 24 Then
        img13.Left = img25.Left
        img13.Top = img25.Top
    Else
        img13.Left = m
        img13.Top = n
        nstate1 = 0
        
        
    
    End If
End Sub ]

il primo codice nel timer 1 mi viene  .. poi dopo timer 1 non viene aiuto... mi serve per presentarlo a scuola grazie

PM
Avatar
poeo85 (Normal User)
Pro


Messaggi: 104
Iscritto: 27/01/2010

Up
1
Down
V
Segnala al moderatore
Postato alle 13:05
Mercoledì, 26/01/2011
ho fatto un immagine del form di come l'ho fatto...
a me funziona

domanda:
hai caricato nelle image una immagine o cambiato la proprietà Border Style in 1 _ fixed single? altrimenti non vedi nulla


poeo85 ha allegato un file: form.JPG (13291 bytes)
Clicca qui per guardare l'immagine
PM
Avatar
poeo85 (Normal User)
Pro


Messaggi: 104
Iscritto: 27/01/2010

Up
1
Down
V
Segnala al moderatore
Postato alle 14:01
Mercoledì, 26/01/2011
questo è il progetto con form che funziona


poeo85 ha allegato un file: move.zip (2009 bytes)
Clicca qui per scaricare il file
PM
Avatar
poeo85 (Normal User)
Pro


Messaggi: 104
Iscritto: 27/01/2010

Up
0
Down
V
Segnala al moderatore
Postato alle 13:08
Martedì, 25/01/2011
Testo quotato

Postato originariamente da capokkia89:

  ho un piccolo problema sto facendo un programmino semplice .. dovrei simulare un sitema simplex ,half duplex e full duplex .
ecco il codice
[Dim x As Long
Dim y As Long
Dim m As Long
Dim n As Long

Dim nState As Integer
Dim nstate1 As Integer


Private Sub Command1_Click()
    x = img1.Left
    y = img1.Top
    Timer1.Interval = 500
    Timer1.Enabled = True
End Sub

Private Sub Command2_Click()
    Timer1.Enabled = False
End Sub


Private Sub Timer1_Timer()
    nState = nState + 1
    If nState = 1 Then
        img1.Left = img2.Left
        img1.Top = img2.Top
    ElseIf nState = 2 Then
        img1.Left = img3.Left
        img1.Top = img3.Top
    ElseIf nState = 3 Then
        img1.Left = img4.Left
        img1.Top = img4.Top
    ElseIf nState = 4 Then
        img1.Left = img5.Left
        img1.Top = img5.Top
    ElseIf nState = 5 Then
        img1.Left = img6.Left
        img1.Top = img6.Top
    ElseIf nState = 6 Then
        img1.Left = img7.Left
        img1.Top = img7.Top
    ElseIf nState = 7 Then
        img1.Left = img8.Left
        img1.Top = img8.Top
    ElseIf nState = 8 Then
        img1.Left = img9.Left
        img1.Top = img9.Top
    ElseIf nState = 9 Then
        img1.Left = img10.Left
        img1.Top = img10.Top
    ElseIf nState = 10 Then
        img1.Left = img11.Left
        img1.Top = img11.Top
    ElseIf nState = 11 Then
        img1.Left = img12.Left
        img1.Top = img12.Top
    Else
        img1.Left = x
        img1.Top = y
        nState = 0
        
        
    
    End If
End Sub

Private Sub Command3_Click()
    m = img13.Left
    n = img13.Top
    Timer2.Interval = 1000
    Timer2.Enabled = True
End Sub

Private Sub Command4_Click()
    Timer2.Enabled = False
End Sub



Private Sub Timer2_Timer()
    nstate1 = nstate1 + 1
    If nstate1 = 13 Then
        img13.Left = img14.Left
        img13.Top = img14.Top
    ElseIf nstate1 = 14 Then
        img13.Left = img15.Left
        img13.Top = img15.Top
    ElseIf nstate1 = 15 Then
        img13.Left = img16.Left
        img13.Top = img16.Top
    ElseIf nstate1 = 16 Then
        img13.Left = img17.Left
        img13.Top = img17.Top
    ElseIf nstate1 = 17 Then
        img13.Left = img18.Left
        img13.Top = img18.Top
    ElseIf nstate1 = 18 Then
        img13.Left = img19.Left
        img13.Top = img19.Top
    ElseIf nstate1 = 19 Then
        img13.Left = img20.Left
        img13.Top = img20.Top
    ElseIf nstate1 = 20 Then
        img13.Left = img21.Left
        img13.Top = img21.Top
    ElseIf nstate1 = 21 Then
        img13.Left = img22.Left
        img13.Top = img22.Top
    ElseIf nstate1 = 22 Then
        img13.Left = img23.Left
        img13.Top = img23.Top
    ElseIf nstate1 = 23 Then
        img13.Left = img24.Left
        img13.Top = img24.Top
    ElseIf nstate1 = 24 Then
        img13.Left = img25.Left
        img13.Top = img25.Top
    Else
        img13.Left = m
        img13.Top = n
        nstate1 = 0
        
        
    
    End If
End Sub ]

il primo codice nel timer 1 mi viene  .. poi dopo timer 1 non viene aiuto... mi serve per presentarlo a scuola grazie



e un polmone nuovo grazie!!!
spiega qual'è il problema per favore, cosa c'è che non va? il programma che deve fare? che cosa non fa?


allora nella formo ho messo due immagini :la prima è la sorgente , il secondo il destinatario. - capokkia89 - 25/01/11 13:11
scusa sono nuovo come faccio a fare un nuovo commento grande e nn come quello che ho aggiunto poco fa - capokkia89 - 25/01/11 13:12
invece di commento premi su rispondi!!! - poeo85 - 25/01/11 13:16
PM
Avatar
capokkia89 (Normal User)
Newbie


Messaggi: 8
Iscritto: 25/01/2011

Up
0
Down
V
Segnala al moderatore
Postato alle 13:37
Martedì, 25/01/2011
>> >> allora in una form ho messo  due immagini uno è la sorgente e l'altra il destinatario
>> >> poi in una image ho messo una immagine  allora questo con il timer 1 si muove fino ad arrivare al destinatario  questa parte mi funziona , poi per simulare la trasmissione half duplex il destinatario deve rispondere alla sorgente.. e quando faccio invia nella command bottom del destinario non succede nulla l'immagine resta fissa..
>>

PM
Avatar
poeo85 (Normal User)
Pro


Messaggi: 104
Iscritto: 27/01/2010

Up
0
Down
V
Segnala al moderatore
Postato alle 13:44
Martedì, 25/01/2011
http://www.pierotofy.it/pages/extras/forum/6/1021625-come_ ...


guarda l'esempio che ho postato qua...
incolla due shape nel form e muovi la seconda shape con le freccette...


nel tuo caso non ti resta che
1_ al posto delle shape metti le due image che ti servono

2_invece di mettere che il movimento venga effettuato alla pressione delle frecce lo metti dentro ai timer se devi farlo con i timer.


non dovresti aver problemi a capire ma nel caso contrario chiedi pure aiuto con la spiegazione o la domanda di ciò che non è chiaro

PM
Avatar
capokkia89 (Normal User)
Newbie


Messaggi: 8
Iscritto: 25/01/2011

Up
0
Down
V
Segnala al moderatore
Postato alle 14:03
Martedì, 25/01/2011
me lo potresti spiegare meglio che nn ci sto capendo niente scusa...

PM
Avatar
poeo85 (Normal User)
Pro


Messaggi: 104
Iscritto: 27/01/2010

Up
0
Down
V
Segnala al moderatore
Postato alle 14:22
Martedì, 25/01/2011
allora alla fin fine il tuo problema è spostare una image dal punto A a B.

per spostare l'image nella programmazione si modifica il valore della proprietà left dell'oggetto da spostare.

se lo spostamento è da sinistra a destra la incrementerai
se lo spostamento è da destra a sinistra decrementerai il valore.

nel tuo caso

metti questo codice nel form che ha 4 bottoni, 2 timer e 2 image (chiamate img1 e img2)

Option Explicit
Private Sub Command1_Click()
    Timer1.Interval = 500
    Timer1.Enabled = True
End Sub

Private Sub Command2_Click()
    Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
    If img2.Left + img2.Width > img1.Left Then
        Timer1.Enabled = False
    Else
        img2.Left = img2.Left + 100
    End If
End Sub

Private Sub Command3_Click()
    Timer2.Interval = 1000
    Timer2.Enabled = True
End Sub

Private Sub Command4_Click()
    Timer2.Enabled = False
End Sub

Private Sub Timer2_Timer()
    If img2.Left + img2.Width > img1.Left Then
        Timer2.Enabled = False
    Else
        img2.Left = img2.Left - 100
    End If
End Sub

è quello che volevi?

chiedi ciò che non è chiaro....

Ultima modifica effettuata da poeo85 il 25/01/2011 alle 14:23
PM
Avatar
capokkia89 (Normal User)
Newbie


Messaggi: 8
Iscritto: 25/01/2011

Up
0
Down
V
Segnala al moderatore
Postato alle 10:37
Mercoledì, 26/01/2011
non succede nulla..!! devo dichiarare qualche variabile??

PM
Pagine: [ 1 2 ] Precedente | Prossimo