Solved

MANUAL NAVIGATION AT FLOWLAYOUT PANEL

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple file Upload asp.net 2 38
Open a word document 23 33
Change Format on Data when exporting to Excel 4 23
Advice on Xojo as a development tool over VB. 4 31
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now