IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Problème de Scrollbar


Sujet :

VB.NET

  1. #1
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Août 2012
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Services de proximité

    Informations forums :
    Inscription : Août 2012
    Messages : 74
    Par défaut Problème de Scrollbar
    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!

  2. #2
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 198
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Août 2012
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Services de proximité

    Informations forums :
    Inscription : Août 2012
    Messages : 74
    Par défaut
    Merci mais je ne comprends pas trop...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    Protected Overridable Function ScrollToControl ( _
    	activeControl As Control _
    ) As Point
    'Utilisation
    Dim activeControl As Control
    Dim returnValue As Point
     
    returnValue = Me.ScrollToControl(activeControl)
    Ces lignes de code sont à placer au tout début?
    Dois-je remplacer activecontrol par le panel contenant mes photos?
    Merci de m'aiguiller un peu plus...

  4. #4
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 198
    Par défaut
    je n'avais pas regardé le code ...

    Application.DoEvents en plus d'être peu recommandé ne sert strictement à rien dans un autre thread

    le picturebox devrait être créé le reportprogress plutot que dans le dowork

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    scrolltocontrol(le picturebox que tu voudrais voir en haut)

    Je voudrais déplacer automatiquement la scrollbar à chaque nouvel écran
    ce qui veut dire ?
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  5. #5
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Août 2012
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Services de proximité

    Informations forums :
    Inscription : Août 2012
    Messages : 74
    Par défaut
    Merci pour ta réponse. C'est vrai que je me suis mal exprimé...
    En fait, j'arrive à afficher 40 photos à la fois et je voudrais qu'à la quarantième la photo s'affiche tout en haut de l'écran comme si j'avais cliqué sur la scrollbar.
    J'ai essayé avec ceci mais sans résultat (aucune action rendu)
    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
     
    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) & ")"
            If x = 15 And y = 775 Then : ScrollToControl(Gadget) : End If
            tempChild.Refresh()
        End Sub

  6. #6
    Membre actif
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Août 2012
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Services de proximité

    Informations forums :
    Inscription : Août 2012
    Messages : 74
    Par défaut
    Personne ne peut m'aider à résoudre mon problème?

Discussions similaires

  1. problème de scrollbar inactive
    Par sissi25 dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 22/09/2007, 14h24
  2. [XHTML] Doctype XHTML et problème de scrollbar
    Par darwin22 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 10
    Dernier message: 09/03/2007, 14h23
  3. [C#][datagrid] problème de scrollbar
    Par d1g-2-d1g dans le forum Windows Forms
    Réponses: 4
    Dernier message: 19/05/2006, 16h26
  4. Problème de Scrollbar
    Par JeanECN dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 22/03/2006, 23h07
  5. Adaptation d'un code TMemo vers TRichEdit : problème de ScrollBars
    Par Droïde Système7 dans le forum Composants VCL
    Réponses: 2
    Dernier message: 21/01/2005, 15h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo