Ball rebondissante dans une application

Publié le par P1l0u



Comment créé une Ball rebondissante dans une application !

Video de démonstration :

 

Codes sources :

Public Class Form1
    Dim m_Dx As Integer
    Dim m_Dy As Integer
    Dim m_X As Integer
    Dim m_Y As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim rnd As New Random
        m_Dx = rnd.Next(1, 4)
        m_Dy = rnd.Next(1, 4)
        m_X = rnd.Next(0, Me.ClientSize.Width - 75)
        m_Y = rnd.Next(0, Me.ClientSize.Height - 75)
    End Sub
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        e.Graphics.Clear(Me.BackColor)
        e.Graphics.FillEllipse(Brushes.Yellow, m_X, m_Y, 25, 25)
        e.Graphics.DrawEllipse(Pens.Yellow, m_X, m_Y, 25, 25)
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        m_X += m_Dx
        If m_X < 0 Then
            m_Dx = -m_Dx
            Beep()
        ElseIf m_X + 50 > Me.ClientSize.Width Then
            m_Dx = -m_Dx
            Beep()
        End If
        m_Y += m_Dy
        If m_Y < 0 Then
            m_Dy = -m_Dy
            Beep()
        ElseIf m_Y + 50 > Me.ClientSize.Height Then
            m_Dy = -m_Dy
            Beep()
        End If
        Me.Invalidate()
    End Sub
End Class

Attention :  Il ne faut pas oublié de rajouter un Timer , ainsi que de mettre la valeur enabled à TRUE

 

 

Cordialement P1l0u

Publié dans Codes sources

Pour être informé des derniers articles, inscrivez vous :
Commenter cet article
P
<br /> y manqu e un compteur mmmmmm<br /> <br /> <br />
Répondre