Bonjour.
Je crois que je n'ai pas bien assimilé la notion de variable globale:

je cherche a faire bouger le panel: ce code marche:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Public Class Form1
    Dim x As Integer = 0
    'Dim p As New Point(x, x)
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.Timer1.Interval = 50
        x += 5
        Dim p As New Point(x, x)
        Me.Panel1.Location = p
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim p As New Point(x, x)
        Me.Panel1.Location = p
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Timer1.Enabled = False
    End Sub
End Class
mais ce code ne marche pas:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Public Class Form1
    Dim x As Integer = 0
    Dim p As New Point(x, x)
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.Timer1.Interval = 50
        x += 5
        'Dim p As New Point(x, x)
        Me.Panel1.Location = p
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim p As New Point(x, x)
        Me.Panel1.Location = p
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Timer1.Enabled = False
    End Sub
End Class
Merci