Bonjour à tous,
Je viens de créer sous vb.net 2010 un petit programme qui affiche des photos.
J'en ai 300 à afficher à raison de 4 lignes par pages. Je voudrais déplacer automatiquement la scrollbar à chaque nouvel écran (5ème ligne-10ème ligne etc...).
pour le moment j'ai mis ceci mais ça ne fonctionne pas:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
If y = 775 And x = 1695 Then : Me.AutoScrollPosition = New Point(Me.AutoScrollPosition.X, Me.AutoScrollPosition.Y + 1030) : End If
Voici mon programme:
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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
Public Class Vidéo
    Public NomSite As String
    Public Repertoire As String
    Public FichierIni As String
    Public FichierVideo As String
    Public SystemIni As String = WindowsApplication1.Menu.SystemIni
    Dim RepertoireSysteme As String = WindowsApplication1.Menu.RepertoireSysteme
    Public RFichierIni As Boolean
    Private Sub Vidéo_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.F4 AndAlso (e.Alt) Then
            WindowsApplication1.Menu.AfficherMasquerBouton(0)
            Dim form1 As New Site
            form1.MdiParent = WindowsApplication1.Menu
            form1.Dock = DockStyle.Fill
            form1.Top = 30
            form1.Show()
        End If
        Select Case e.KeyCode
            Case Keys.Delete
                Dim Reponse As Integer
                Dim Fichier As String = WindowsApplication1.Menu.LabelItem14.Text
                If Fichier <> "" Then
                    Reponse = MsgBox("Etes-vous sur de vouloir supprimer " & Fichier & "?", MsgBoxStyle.YesNo)
                    If Reponse = 6 Then
                        Dim Image As String = Microsoft.VisualBasic.Left(Fichier, Len(Fichier) - 3) & "jpg"
                        System.IO.File.Delete(Repertoire & Fichier)
                        If System.IO.File.Exists(Repertoire & Image) Then
                            System.IO.File.Delete(Repertoire & Image)
                        End If
                        Dim Gadget As Integer = Val(LireINI("Videos", "Gadget", SystemIni)) + 1
                        Me.Controls.Item(Gadget).Visible = False
                        RFichierIni = True
                        'Me.BackgroundWorker1.WorkerReportsProgress = True
                        'Me.BackgroundWorker1.WorkerSupportsCancellation = True
                        'Me.BackgroundWorker1.RunWorkerAsync(New Object() {1})
                    End If
                End If
        End Select
    End Sub
    Private Sub Vidéo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Repertoire = LireINI(NomSite, "Repertoire", SystemIni)
        EcrireINI("Videos", "Gadget", "1", WindowsApplication1.Menu.SystemIni)
        WindowsApplication1.Menu.LabelItem14.Text = ""
        WindowsApplication1.Menu.LabelItem24.Text = WindowsApplication1.Menu.LabelItem1.Text
        NomSite = WindowsApplication1.Menu.LabelItem24.Text
        Repertoire = LireINI(NomSite, "Repertoire", WindowsApplication1.Menu.SystemIni)
        FichierIni = Repertoire & "Fichiers.ini"
        Me.AutoScroll = True
        Me.BackgroundWorker1.WorkerReportsProgress = True
        Me.BackgroundWorker1.WorkerSupportsCancellation = True
        Me.BackgroundWorker1.RunWorkerAsync(New Object() {1})
    End Sub
    Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim Nombre, Ajouter, Index, x, y, Compte As Integer
        x = 15
        y = 10
        Index = 0
        Nombre = Val(LireINI("Menu", "Nombre", FichierIni))
        Dim Choix As Integer = e.Argument(0)
        For Compte = 1 To Nombre
            Dim Fichier As String = LireINI("Menu", Str(Compte), FichierIni)
            Select Case Choix
                Case 1 : Ajouter = 1
                Case 2 : If LireINI(Fichier, "DecoupeVideo", FichierIni) = "1" Then : Ajouter = 1 : Else : Ajouter = 0 : End If
                Case 3 : If LireINI(Fichier, "DecoupeVideo", FichierIni) = "0" Then : Ajouter = 1 : Else : Ajouter = 0 : End If
                Case 4 : If LireINI(Fichier, "DecoupeExtrait", FichierIni) = "1" Then : Ajouter = 1 : Else : Ajouter = 0 : End If
                Case 5 : If LireINI(Fichier, "DecoupeExtrait", FichierIni) = "0" Then : Ajouter = 1 : Else : Ajouter = 0 : End If
            End Select
            If Ajouter = 1 Then
                Index += 1
                EcrireINI("Videos", Str(Index), Fichier, SystemIni)
                Fichier = Repertoire & Mid(Fichier, 1, Len(Fichier) - 3) & "jpg"
                Dim Gadget As New PictureBox
                Me.BackgroundWorker1.ReportProgress(Nothing, New Object() {Gadget, Compte, x, y, Fichier, Nombre})
                x += 210
                If x = 1905 Then : x = 15 : y += 255 : End If
                Application.DoEvents()
            End If
        Next
    End Sub
    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        Dim Gadget As PictureBox = TryCast(e.UserState(0), PictureBox)
        Dim Compte As Integer = e.UserState(1)
        Dim x As Integer = e.UserState(2)
        Dim y As Integer = e.UserState(3)
        Dim Fichier As String = e.UserState(4)
        Dim Nombre As Integer = e.UserState(5)
        If System.IO.File.Exists(Fichier) = True Then
            Dim FichierImage As New System.IO.FileStream(Fichier, System.IO.FileMode.Open)
            Gadget.BackgroundImage = Image.FromStream(FichierImage)
            FichierImage.Close()
        End If
        Dim NomFichier As New System.IO.FileInfo(Fichier)
        Gadget.Name = "Image" & Trim(Str(Compte))
        Gadget.Height = 245
        Gadget.Width = 190
        Gadget.Left = x
        Gadget.Top = y
        Gadget.Visible = False
        Gadget.BorderStyle = BorderStyle.Fixed3D
        Gadget.BackgroundImageLayout = ImageLayout.Stretch
        Gadget.Cursor = Cursors.Hand
        Dim tooltip As New ToolTip
        tooltip.SetToolTip(Gadget, NomFichier.Name)
        Gadget.Visible = True
        Dim tempChild As Vidéo = CType(WindowsApplication1.Menu.MdiChildren(0), Form)
        tempChild.Controls.Add(Gadget)
        tempChild.GroupPanel1.Visible = True
        tempChild.Label2.Text = "Création des vignettes(" & Str(Compte) & "/" & Str(Nombre) & ")"
        tempChild.Refresh()
        If y = 775 And x = 1695 Then : Me.AutoScrollPosition = New Point(Me.AutoScrollPosition.X, Me.AutoScrollPosition.Y + 1030) : End If
    End Sub
    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        Dim tempChild As Vidéo = CType(WindowsApplication1.Menu.MdiChildren(0), Form)
        tempChild.GroupPanel1.Visible = False
        tempChild.AutoScrollMinSize = New Size(0, (CInt(tempChild.Controls.Count / 9) * 280) + 20)
    End Sub
End Class
Merci à vous tous pour votre aide!