Solved

MANUAL NAVIGATION AT FLOWLAYOUT PANEL

Posted on 2011-02-13
4
647 Views
Last Modified: 2012-05-11
Hi All,

I want to show images to flp, let's 5 images per page.
Let's say we have 20 images.

I want to paging them using button.

How could I do it?

Thank you.
0
Comment
Question by:emi_sastra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34883626
Here's a basic example:
Public Class Form1

    Private Index As Integer = 0
    Private Panels As New List(Of Panel)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim di As New System.IO.DirectoryInfo("C:\Users\Mike\Pictures")
        For Each fi As System.IO.FileInfo In di.GetFiles("*.jpg")
            Dim pnl As New Panel
            pnl.BorderStyle = BorderStyle.FixedSingle
            pnl.Size = New Size(100, 100)
            pnl.Margin = New Padding(10)

            Dim pb As New PictureBox
            pb.Dock = DockStyle.Fill
            pb.SizeMode = PictureBoxSizeMode.Zoom
            pb.Image = Image.FromFile(fi.FullName)

            Dim lbl As New Label
            lbl.AutoSize = False
            lbl.Text = System.IO.Path.GetFileNameWithoutExtension(fi.Name)
            lbl.TextAlign = ContentAlignment.MiddleCenter
            lbl.Dock = DockStyle.Bottom

            pnl.Controls.Add(lbl)
            pnl.Controls.Add(pb)
            Panels.Add(pnl)
        Next
        DisplayImages()
    End Sub

    Private Sub DisplayImages()
        FlowLayoutPanel1.Controls.Clear()
        For i As Integer = Index To Index + 4
            If i < Panels.Count Then
                FlowLayoutPanel1.Controls.Add(Panels(i))
            End If
        Next
        btnPrevious.Enabled = (Index > 0)
        btnNext.Enabled = ((Index + 5) <= (Panels.Count - 1))
    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If Index > 0 Then
            Index = Index - 4
            If Index < 0 Then
                Index = 0
            End If
            DisplayImages()
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If Index < Panels.Count - 1 Then
            Index = Index + 4
            If Index > Panels.Count - 1 Then
                Index = Panels.Count - 1
            End If
            DisplayImages()
        End If
    End Sub

End Class

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 34884020
Here's another example...this one only loads the 5 images being displayed when the Prev/Next buttons are pressed:
Public Class Form1

    Private Index As Integer = 0
    Private FileNames As New List(Of String)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim di As New System.IO.DirectoryInfo("C:\Users\Mike\Pictures")
        For Each fi As System.IO.FileInfo In di.GetFiles("*.jpg")
            FileNames.Add(fi.FullName)
        Next
        DisplayImages()
    End Sub

    Private Sub DisplayImages()
        FlowLayoutPanel1.Controls.Clear()
        For i As Integer = Index To Index + 4
            If i < FileNames.Count Then
                Dim pnl As New Panel
                pnl.BorderStyle = BorderStyle.FixedSingle
                pnl.Size = New Size(100, 100)
                pnl.Margin = New Padding(10)

                Dim pb As New PictureBox
                pb.Dock = DockStyle.Fill
                pb.SizeMode = PictureBoxSizeMode.Zoom
                Using fs As New System.IO.FileStream(FileNames(i), IO.FileMode.Open)
                    pb.Image = Image.FromStream(fs)
                End Using

                Dim lbl As New Label
                lbl.AutoSize = False
                lbl.Text = System.IO.Path.GetFileNameWithoutExtension(FileNames(i))
                lbl.TextAlign = ContentAlignment.MiddleCenter
                lbl.Dock = DockStyle.Bottom

                pnl.Controls.Add(lbl)
                pnl.Controls.Add(pb)
                FlowLayoutPanel1.Controls.Add(pnl)
            End If
        Next
        btnPrevious.Enabled = (Index > 0)
        btnNext.Enabled = ((Index + 5) <= (FileNames.Count - 1))
    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If Index > 0 Then
            Index = Index - 4
            If Index < 0 Then
                Index = 0
            End If
            DisplayImages()
        End If
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If Index < FileNames.Count - 1 Then
            Index = Index + 4
            If Index > FileNames.Count - 1 Then
                Index = FileNames.Count - 1
            End If
            DisplayImages()
        End If
    End Sub

End Class

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34884961
Hi Idle_Mind,

It works.

Thank you very much for your help.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question