Question create a photo galery using windows form

elite87

Member
Joined
Aug 13, 2009
Messages
8
Programming Experience
1-3
:confused:

This is my problem.. I have created a photo gallery in web.. was just wondering how to create a interactive in windows form. I wana put in all my pictures in a folder. Then call all the pictures from that folder. I am also wana set a caption for all the images but I dun wana use any db.
Can sum1 please help me?? I am so blur...
need to do sum photo gallery very urgently....

:confused:
 
Hi,

Add a user control in your application. Add a label control & a picturebox in that user control.
Set label1.Dock=Top & PictureBox1.Dock=Fill.

Put the following code in the user control code behind.

Friend imageCaption As String
Protected Friend Sub Show(ByVal filename As String)
label1.Text = imageCaption
pictureBox1.Image = Image.FromFile(filename)
End Sub

Now on the main form where you want to show the photo gallery, add a flowlayoutpanel.

Put the following code in the form...

Dim files As String() = Directory.GetFiles("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\", "*.jpg", SearchOption.TopDirectoryOnly)

If files.Length > 0 Then
Dim uControl As UserControl2
Dim i As Integer = 1
For Each str As String In files
uControl = New UserControl2()
uControl.imageCaption = i.ToString()
uControl.Show(str)
flowLayoutPanel1.Controls.Add(uControl)
i += 1
Next
End If


Compile & run the code, a photo gallery is created.


Thanks
Panna
 
VB.NET:
Imports System.IO
Imports System.Windows.Forms.UserControl


Public Class galery
  
    Private Sub galery_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim strFileSize As String = ""
        Dim di As New IO.DirectoryInfo("C:\Documents and Settings\RKRRKAN\My Documents\Downloads\TestExcel2\TestExcel2\chihuhua")
        Dim aryFi As IO.FileInfo() = di.GetFiles("*.jpg")
        Dim fi As IO.FileInfo

        Dim j As Integer
        j = 0
        For Each fi In aryFi
            j = j + 1
        Next


        Dim test(j) As PictureBox
        Dim Blue(j) As Label
        Dim i As Integer
        i = 0
        Dim h As Integer
        h = 1
        For Each fi In aryFi
            ' strFileSize = (Math.Round(fi.Length / 1024)).ToString()
            test(i) = New PictureBox
            test(i).BackgroundImage = Image.FromFile("C:\Documents and Settings\My Documents\Downloads\TestExcel2\chihuhua\" & fi.Name)
            test(i).BackgroundImageLayout = ImageLayout.Stretch

            test(i).Width = 100
            test(i).Height = 100
            test(i).Top = 373
            test(i).Left = 220
            test(i).Location = New Point(69, 156 + h)
            test(i).Visible = True
            test(i).Name = "test" & i

            Dim str As String
            str = System.IO.Path.GetFileNameWithoutExtension("C:\Documents and Settings\My Documents\Downloads\TestExcel2\chihuhua\" & fi.Name)

            Blue(i) = New Label
            Blue(i).Name = "caption" & i
            Blue(i).Text = str
            Blue(i).Location = New Point(180, 156 + h)
            Blue(i).BackColor = Color.Black
            Blue(i).ForeColor = Color.DarkOrange
            Blue(i).Visible = True

            Me.Controls.Add(test(i))
            Me.Controls.Add(Blue(i))
            i = i + 1
            h = h + 100
            '  MsgBox(fi.Name)
        Next
        ' MsgBox(i)
    End Sub
End Class


This is my code... wat i gt is just 4 pictures as i 4 pictures in my folder....

but wat i want is nt this... i wana mk it 1 big image at the form. then i hv the 123 button depending number of images in the folder.... hw to do tat???
 
Then instead of user control, you can add a flowlayoutpanel and a picturebox into the form and do like the following...

Private files As String()

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
files = Directory.GetFiles("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\", "*.jpg", SearchOption.TopDirectoryOnly)

If files.Length > 0 Then
Dim lnkLbl As LinkLabel
For i As Integer = 0 To files.Length - 1
lnkLbl = New LinkLabel()
lnkLbl.Name = "lnkLbl" & (i + 1).ToString()
lnkLbl.Text = (i + 1).ToString()
pnlTop.Controls.Add(lnkLbl) 'Add linklabel to the flowlayout panel
AddHandler lnkLbl.LinkClicked, AddressOf lnkLbl_LinkClicked
Next
pictureBox1.Image = Image.FromFile(files(0))
End If
End Sub

Private Sub lnkLbl_LinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventArgs)
Dim link As LinkLabel = DirectCast(sender, LinkLabel)
pictureBox1.Image = Image.FromFile(files(Integer.Parse(link.Text) - 1))
End Sub
 
Back
Top