Commen faire un bouton suivant precedent

alainxp Messages postés 18 Date d'inscription mercredi 29 janvier 2003 Statut Membre Dernière intervention 20 novembre 2009 - 28 avril 2003 à 17:53
mayssoun22 Messages postés 1 Date d'inscription mardi 29 novembre 2005 Statut Membre Dernière intervention 30 novembre 2005 - 30 nov. 2005 à 12:45
salut je debut ; donc j ai pas trop de connaisance je crée un log sur des imgs :
j ai un filesbox et un picturebox comment doit je faire merci

Private Sub Form_Load()
File1.Pattern = "*.jpg"
File1.Path = App.Path

End Sub

Private Sub file1_click()
Image1.Picture = LoadPicture((App.Path) + "" + (File1.FileName))
End Sub

2 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
28 avril 2003 à 18:40
il te faut conserver une trace des fichiers visualisés. Pour cela , rien de plus simple, tu crée un Tableau de chaine de caracteres
Dim mesFichiers() as string
. De plus, tu aura besoin d'une valeur qui t'indique le fichier courant , dans cette liste. un entier devrait amplement convenir !!

'tableau de nom de fichiers
Dim MesFichiers() As String
Dim Courant As Integer

'bouton precedent
Private Sub Command1_Click()
    If Courant > 1 Then 'si l'on est pas au debut
        Courant = Courant - 1 ' regarde l'element precedent
        Command2.Enabled = True ' allume le bouton suivant        If Courant 1 Then Command1.Enabled False 'grise le bouton si necessaire
    End If
    'mettre ici le chargement
    Label1.Caption = MesFichiers(Courant)
End Sub

'bouton suivant
Private Sub Command2_Click()
    'UBound renvoie la taille Max du tableau dynamique
    If Courant < UBound(MesFichiers) Then 'si on est pas a la fin du tableau
        Courant = Courant + 1 ' on regardes le suivant
        Command1.Enabled = True 'on donne la possibilite de revenir.        If Courant UBound(MesFichiers) Then Command2.Enabled False 'si on est a la fin , on grise le bouton
    End If
    'on affiche l'element 'ajouter ici le chargement de l'image (LoadPicture......)
    Label1.Caption = MesFichiers(Courant)
End Sub

'bouton ajouter
Private Sub Command3_Click()
    'le premier ajout provoque une erreur , que l'on recupere
    On Error GoTo Taille0
    Courant = Courant + 1
    'on agrandit le tableau
    ReDim Preserve MesFichiers(Courant)
    MesFichiers(Courant) = "Fichier " & Courant
    
    'on allume le bouton precedent , si necessaire
    If Courant > 1 Then Command1.Enabled = True
Fin:
    Label1.Caption = MesFichiers(Courant)
    Command2.Enabled = False
Exit Sub
Taille0:
    'donne une taille 0 et initialise la premiere case du tableau
    ReDim MesFichiers(1)
    MesFichiers(1) = "Fichier 1"
    GoTo Fin
End Sub

Private Sub Form_Load()
    'initialisation des controles
    Label1.Caption = "aucune image chargee"
    Label1.AutoSize = True
    Command1.Caption = "Precedent"
    Command2.Caption = "Suivant"
    Command3.Caption = "Charger une image"
    Command1.Enabled = False
    Command2.Enabled = False
End Sub

0
mayssoun22 Messages postés 1 Date d'inscription mardi 29 novembre 2005 Statut Membre Dernière intervention 30 novembre 2005
30 nov. 2005 à 12:45
bonjour tout le monde,
je suis un nouveau membre dans ce club et je souhaite vraiment que vous m'aidiez,en fait j'ai besoin du code du bouton "suivant"et "precedent"
merci d'avance


a+
0
Rejoignez-nous