csharp

Create Image Gallery In Windows Form Using VB.net

In this article, we will learn how to create image gallery in Windows Form Using VB.net.

Click This Link ForCreate Image Gallery In Windows Form using C#
Listview: Listview is a control it is basically used for display item in different views like Large, Small, list, Tile and Details.
ScreenShot Describe output After Run The Project:
Screenshot
In this tutorial, we will learn a simple way to create Image viewer in c# using Listview.
Step 1. Open visual studio clicks on the New project–>”Visual Basic”–>”Windows Form Application”.Write the name of a project like “ImagegalleryListView”.

Step 2. Open Form1 Design page drop one listView, one Button and four radio Button List.Design your page like screenshot.

Step 3.Double Click on Open Button “button_click” event generated. After that simply put this code on your form1.cs page.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports System.IO
Namespace ImageGalleryListView
	Public Partial Class Form1
		Inherits Form

		Private myImageList As System.Windows.Forms.ImageList = New ImageList()
		Private myImageListSmall As System.Windows.Forms.ImageList = New ImageList()
		Private myImageListLarge As System.Windows.Forms.ImageList = New ImageList()
		Private count As Integer = 0
		Private ofd As New OpenFileDialog() With { _
			Key .Multiselect = True, _
			Key .ValidateNames = True, _
			Key .Filter = "JPG|*jpg|JPEG|*.jpeg|PNG|*.png" _
		}
		Private fi As FileInfo

		Public Sub New()
			InitializeComponent()
			listViewFile.SmallImageList = myImageListSmall

			listViewFile.SmallImageList = myImageListLarge
		End Sub

		Private Sub buttonOpen_Click(sender As Object, e As EventArgs)
			myImageList.ImageSize = New Size(50, 50)
			myImageListSmall.ImageSize = New Size(32, 32)
			myImageListLarge.ImageSize = New Size(80, 80)
			If ofd.ShowDialog() = DialogResult.OK Then
				listViewFile.Items.Clear()
				For Each fileName As String In ofd.FileNames
					fi = New FileInfo(fileName)
					Dim fileinfo As New FileInfo(fileName)
					Using stream As New  FileStream(fi.FullName, FileMode.Open, FileAccess.Read)
						myImageList.Images.Add(Image.FromStream(stream))
						myImageListSmall.Images.Add(Image.FromStream(stream))


						myImageListLarge.Images.Add(Image.FromStream(stream))
					End Using
					listViewFile.LargeImageList = myImageList
					listViewFile.Items.Add(New ListViewItem() With { _
						Key .ImageIndex = count, _
						Key .Text = fi.Name, _
						Key .Tag = fi.FullName _
					})
					count += 1
				Next
			End If


		End Sub
                //Code for large Image icon 
               //Generate event for CheckedChanged

		Private Sub radioButtonLarge_CheckedChanged(sender As Object, e As EventArgs)
			If radioButtonLarge.Checked = True Then
				listViewFile.LargeImageList = myImageListLarge
				listViewFile.View = View.LargeIcon
			End If
		End Sub
                 //Code for Small Image icon 
                //Generate event for CheckedChanged

		Private Sub radioButtonSmall_CheckedChanged(sender As Object, e As EventArgs)
			If radioButtonSmall.Checked = True Then
				listViewFile.SmallImageList = myImageListSmall

				listViewFile.View = View.SmallIcon
			End If
		End Sub
                //Code for List Image icon 
               //Generate event for CheckedChanged

		Private Sub radioButtonList_CheckedChanged(sender As Object, e As EventArgs)

			If radioButtonList.Checked = True Then

				listViewFile.View = View.List
			End If
		End Sub
              
	End Class
End Namespace

Advertisement
Advertisement

1 thought on “Create Image Gallery In Windows Form Using VB.net

Leave a Reply

Your email address will not be published. Required fields are marked *