|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Junior Member
Iscritto dal: Dec 2008
Messaggi: 2
|
[VB] Spostare palla
Salve a tutti!!
vi scrivo per chiedervi un piccolo aiuto per un programmino di VB: sono al terzo anno di liceo e per il primo anno mi trovo ad affrontare questo genere di programma e vorrei sapere come posso fare a: con un solo timer a spostare una pallina per la form con i tasti W E R S D Z X C rispettivamente in diagonale verso l'alto a dx, su , in diagonale verso l'alto a sx, a dx, a sx, diagonale bassa a sx, giù e infine in diagonale bassa a dx. l'unica indicazione che ci è stata data dall'insegnante e stata: Private sub frm_keypress(keyascii as integer) carattere=chr(keyascii) end sub io sono solo riuscita a farlo così con 8 timer: Private Sub Form_KeyPress(KeyAscii As Integer) carattere = Chr(KeyAscii) If carattere = "d" Then Tm1.Enabled = True End If If carattere = "s" Then Tm2.Enabled = True End If If carattere = "x" Then Tm3.Enabled = True End If If carattere = "" Then Tm5.Enabled = True End If If carattere = "e" Then Tm6.Enabled = True End If If carattere = "w" Then Tm7.Enabled = True End If If carattere = "r" Then Tm8.Enabled = True End If If carattere = "z" Then Tm9.Enabled = True End If If carattere = "c" Then Tm4.Enabled = True End If End Sub Private Sub Tm1_Timer() ShpPalla.Left = ShpPalla.Left + 25 If ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width Then Tm1.Enabled = False End If End Sub Private Sub Tm2_Timer() ShpPalla.Left = ShpPalla.Left - 25 If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) Then Tm2.Enabled = False End If End Sub Private Sub Tm3_Timer() ShpPalla.Top = ShpPalla.Top + 25 If ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height Then Tm3.Enabled = False End If End Sub Private Sub Tm4_Timer() ShpPalla.Left = ShpPalla.Left + 25 ShpPalla.Top = ShpPalla.Top + 25 If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) And (ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height) Then Tm4.Enabled = False End If End Sub Private Sub Tm6_Timer() ShpPalla.Top = ShpPalla.Top - 25 If (ShpPalla.Top < frm1.ScaleHeight + ShpPalla.Height) Then Tm6.Enabled = False End If End Sub Private Sub Tm7_Timer() ShpPalla.Left = ShpPalla.Left - 25 ShpPalla.Top = ShpPalla.Top - 25 If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) And (ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height) Then Tm7.Enabled = False End If End Sub Private Sub Tm8_Timer() ShpPalla.Left = ShpPalla.Left + 25 ShpPalla.Top = ShpPalla.Top - 25 If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) And (ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height) Then Tm8.Enabled = False End If End Sub Private Sub Tm9_Timer() ShpPalla.Left = ShpPalla.Left - 25 ShpPalla.Top = ShpPalla.Top + 25 If (ShpPalla.Left <= frm1.ScaleWidth + ShpPalla.Width) And (ShpPalla.Top <= frm1.ScaleHeight + ShpPalla.Height) Then Tm9.Enabled = False End If End Sub grazie mille per l'aiuto^^ ( mi servirebbe entro le sei di stasera se nn è un problema) |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Jun 2002
Città: Dublin
Messaggi: 5989
|
Ti basta un solo timer, ogni volta che viene premuto un tasto salvi il suo valore ASCII come ti ha fatto vedere la prof, e poi nella routine del timer gestisci i vari casi (a seconda del tasto premuto, vai a sinistra, vai a destra, vai giù, etc...).
ciao ![]()
__________________
C'ho certi cazzi Mafa' che manco tu che sei pratica li hai visti mai! |
![]() |
![]() |
![]() |
#3 |
Junior Member
Iscritto dal: Dec 2008
Messaggi: 2
|
grazie!!!!!
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:52.