Bonsoir, je vous explique mon problème, je veux faire déplacer une image, contenue dans une PictureBox aléatoirement dans ma fenêtre. J'y suis arrivé, cependant mon image étant une GIF, son fond est transparent, et lorsqu'elle se déplace, pendant quelques secondes elle garde le fond de l'image de fond de ma Form de là où elle se trouvée avant.
On m'a parlé du double buffering pour la redessiner correctement, mais je ne m'en suis jamais servi, alors je voudrais savoir si quelqu'un peut m'aider, lien, tuto, doc, technique d'approche ?
Voici mon code pour que vous voyez un peu mieux quel est mon problème:
Public Class Form1
Dim Déplacement As Integer = 10
Dim NewPosLeft, NewPosTop As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Left = 0
PictureBox1.Top = 0
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Timer1.Enabled = False
Dim Rand As New Random
NewPosLeft = Rand.Next(Me.Width - PictureBox1.Width)
NewPosTop = Rand.Next(Me.Height - PictureBox1.Height)
NewPosLeft = (Int(NewPosLeft / Déplacement)) * Déplacement
NewPosTop = (Int(NewPosTop / Déplacement)) * Déplacement
Do
Application.DoEvents()
System.Threading.Thread.Sleep(20)
If PictureBox1.Top < NewPosTop Then
PictureBox1.Top += Déplacement
ElseIf PictureBox1.Top > NewPosTop Then
PictureBox1.Top -= Déplacement
End If
If PictureBox1.Left < NewPosLeft Then
PictureBox1.Left += Déplacement
ElseIf PictureBox1.Left > NewPosLeft Then
PictureBox1.Left -= Déplacement
End If
Loop Until PictureBox1.Left NewPosLeft And PictureBox1.Top NewPosTop
End Sub
End Class