Solved

MANUAL NAVIGATION AT FLOWLAYOUT PANEL

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

22 Experts available now in Live!

Get 1:1 Help Now