Simple Image Viewer in vb.net

Image viewer in VB.NET
  1. Imports System.IO
  2. Public Class Form1
  3. Dim index As Integer
  4. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  5. If bdialog.ShowDialog = Windows.Forms.DialogResult.OK Then
  6. TextBox1.Text = bdialog.SelectedPath
  7. index = 0
  8. Me.listbox1.Items.Clear()
  9. For Each Image As String In My.Computer.FileSystem.GetFiles(TextBox1.Text, FileIO.SearchOption.SearchTopLevelOnly) ', "*.gif*", "*.jpg*", "*.bmp*", "*.png*")
  10. Me.listbox1.Items.Add(Image)
  11. index += 1
  12. Next
  13. Button4.Enabled = True
  14. Button5.Enabled = True
  15. Button8.Enabled = True
  16. Button9.Enabled = True
  17. Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
  18. End If
  19. If index > 0 Then
  20. listbox1.SelectedIndex = 0
  21. Else
  22. Me.listbox1.Items.Add("folder is empty")
  23. End If
  24. label2.Text = "total number files in this folder are" & index
  25. End Sub
  26.  
  27. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  28. Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
  29. Try
  30. PictureBox1.Load(TextBox1.Text)
  31. Catch ex As Exception
  32. MsgBox("preview not available", MsgBoxStyle.OkOnly)
  33. End Try
  34.  
  35. End Sub
  36.  
  37.  
  38.  
  39. Private Sub listbox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listbox1.SelectedIndexChanged
  40. TextBox1.Text = listbox1.SelectedItem
  41. End Sub
  42.  
  43. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  44. Me.Close()
  45. End Sub
  46.  
  47. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  48. If Me.ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  49. PictureBox1.BackColor = Me.ColorDialog1.Color
  50. End If
  51. End Sub
  52.  
  53. Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
  54. PictureBox1.BackColor = Color.Transparent()
  55. End Sub
  56.  
  57. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  58. Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
  59. Try
  60. If listbox1.SelectedIndex < index Then
  61. listbox1.SelectedIndex += 1
  62. PictureBox1.Load(listbox1.SelectedItem)
  63. Else
  64. MsgBox("this is the last image", MsgBoxStyle.OkOnly)
  65. End If
  66. Catch ex As Exception
  67. MsgBox("file cannot be diplayed", MsgBoxStyle.OkOnly)
  68. End Try
  69.  
  70. End Sub
  71.  
  72. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  73. Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom
  74. If listbox1.SelectedIndex > 0 Then
  75.  
  76. Try
  77. listbox1.SelectedIndex -= 1
  78. PictureBox1.Load(listbox1.SelectedItem)
  79. Catch ex As Exception
  80. MsgBox("file cannot be diplayed", MsgBoxStyle.OkOnly)
  81. End Try
  82. Else
  83. MsgBox("this is the first image", MsgBoxStyle.OkOnly)
  84. End If
  85. End Sub
  86.  
  87. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  88. End Sub
  89.  
  90. Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
  91. Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
  92. End Sub
  93.  
  94. Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
  95. Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal
  96. End Sub
  97. End Class

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byanupama (not verified)on Fri, 04/20/2012 - 23:18

i tried to run this program bt i don't understand the coding line no 5. and 48. bdialog.ShowDialog = Windows.Forms.DialogResult.OK If Me.ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK plz help me abt it...
Submitted byPinakin Joshi (not verified)on Mon, 12/02/2013 - 23:44

NICE CODING With IMAGES
Submitted byakash561 (not verified)on Sun, 05/11/2014 - 16:45

thank you salman for your code,your list box logic helped me a lot for my project

Add new comment