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
Solved

MANUAL NAVIGATION AT FLOWLAYOUT PANEL

Posted on 2011-02-13
4
634 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
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34883619
0
 
LVL 85

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 85

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 49
.NET tools for adding thread safety to a web app? 3 48
start a process from a service 3 31
How do sunrise and sunset times change with altitude 14 35
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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