Solved

MANUAL NAVIGATION AT FLOWLAYOUT PANEL

Posted on 2011-02-13
4
632 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

770 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