1 Replies - 414 Views - Last Post: 14 November 2019 - 08:25 AM Rate Topic: -----

#1 GiSmO2011   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 27-February 11

Image Gallery (Previous Image-Next Image Issue)

Posted 14 November 2019 - 03:31 AM

Hello everyone,
I ve spend some hours on this issue and I could use your help.
I am loading several images from a folder on a picture box using this code which was found online.
 Public Property Directorypath() As String
        Get
            Return _Directory_Path
        End Get
        Set(ByVal value As String)
          
            _Directory_Path = value
            XLocation = 25
            YLocation = 25
            PicWidth = 200
            PicHeight = 160
            CreateGallery()
        End Set
    End Property
    Dim i As Integer = 0
    Private Sub DrawPictureBox(ByVal _filename As String, ByVal _displayname As String)
        Dim Pic1 As New PictureBox
        Pic1.Location = New System.Drawing.Point(XLocation, YLocation)
        XLocation = XLocation + PicWidth + 20
        If XLocation + PicWidth >= CtrlWidth Then
            XLocation = 25
            YLocation = YLocation + PicHeight + 20
        End If
        Pic1.Name = "PictureBox" & i
        i += 1
        Pic1.Size = New System.Drawing.Size(PicWidth, PicHeight)
        Pic1.TabIndex = 0
        Pic1.TabStop = False
        Pic1.BorderStyle = BorderStyle.Fixed3D


        AddHandler Pic1.MouseClick, AddressOf Pic1_MouseClick
        Me.Controls.Add(Pic1)
        Pic1.Image = Image.FromFile(_filename)
        Pic1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
    End Sub
    Private Sub CreateGallery()
        i = 0
        RemoveControls()
        If Directorypath IsNot Nothing Then
            Dim di As New IO.DirectoryInfo(Directorypath)
            Dim diar1 As IO.FileInfo() = di.GetFiles("*.jpg").Concat(di.GetFiles("*.bmp")).Concat(di.GetFiles("*.png")).Concat(di.GetFiles("*.gif")).ToArray
            Dim dra As IO.FileInfo
            For Each dra In diar1
                DrawPictureBox(dra.FullName, dra.Name)
            Next
        End If
    End Sub 


Using this code

Private Sub Pic1_MouseClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim Pic As PictureBox
        Pic = sender
        Pic.BorderStyle = BorderStyle.FixedSingle
        Pic = CType(sender, PictureBox)
        Form1.PictureBox1.Image = Pic.Image
        Form1.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Form1.Panel1.Visible = True
        Form1.BACK.Visible = False
        Form1.Panel1.AutoScroll = False
    End Sub




when image selected (mouse click) is showed enlarged on a separate picturebox placed in a separate panel.
What I am trying to do is add Previous - Next Image buttons to navigate through the gallery. Any guidelines on this?

Is This A Good Question/Topic? 0
  • +

Replies To: Image Gallery (Previous Image-Next Image Issue)

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15438
  • View blog
  • Posts: 61,857
  • Joined: 12-June 08

Re: Image Gallery (Previous Image-Next Image Issue)

Posted 14 November 2019 - 08:25 AM

Get the list of the files in the directory. It returns an array. Track the index of the array. Next and previous would increment/decrement as needed.


https://docs.microso...etframework-4.8
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1