| | |
Displaying pictures on Windows Forms using subprocedures in VB.NET
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2004
Posts: 1
Reputation:
Solved Threads: 0
Hi All:
I have this code below that uses an open common dialog box to dispay 5 horse pictures.
Does anyone have the code to display the pictures on the Form only by passing the horse picture names as parameters when I call the subprocedure in the mnuViewNext and mnuViewPrevious event handlers?
I set only 2 horse names because I will add 3 names in the add horses event handler later
Thanks
Public Class Form1
Inherits System.Windows.Forms.Form
Dim gstrShortList(4) As String
Dim gintCurrentRecord As Integer
Dim gintNumberOfHorses(4) As Integer
Private Sub DisplayPicture(ByVal intRecord As Integer)
If intRecord < 0 Then
intRecord = 0
End If
If gintNumberOfHorses.IndexOf(gintNumberOfHorses, 0.0) <> -1 Then
If intRecord > gintNumberOfHorses.IndexOf(gintNumberOfHorses, 0.0) - 1 Then
intRecord = gintNumberOfHorses.IndexOf(gintNumberOfHorses, 0.0) - 1
End If
End If
gintCurrentRecord = intRecord
PictureBox1.Image = Image.FromFile(gstrShortList(gintCurrentRecord))
End Sub
Private Function CountHorses() As Integer
Dim intTotalHorses As Integer
Dim intValue As Integer
For Each intValue In gintNumberOfHorses
intTotalHorses += gintNumberOfHorses(intValue)
Next
Return intTotalHorses
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
gstrShortList(0) = "C:\Horse Arabian.jpg"
gstrShortList(1) = "C:\Horse Mustang.jpg"
gintNumberOfHorses(0) = 0
gintNumberOfHorses(1) = 1
End Sub
Private Sub mnuFileHorsePictures_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileHorsePictures.Click
With OpenFileDialog1
With OpenFileDialog1
.Title = "Choose a Picture to Display"
.InitialDirectory = "C:\My HORSES & NICE HORSES Files"
.CheckFileExists = True
.Filter = "Picture files (*.jpg)/*.jpg"
.ShowDialog()
PictureBox1.Image = Image.FromFile(.FileName)
stbInfo.Text = Convert.ToString(CountHorses())
End With
End With
End Sub
Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click
Close()
End Sub
Private Sub mnuViewNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewNext.Click
DisplayPicture(gintCurrentRecord + 1)
End Sub
Private Sub mnuViewPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewPrevious.Click
DisplayPicture(gintCurrentRecord - 1)
End Sub
End Class
I have this code below that uses an open common dialog box to dispay 5 horse pictures.
Does anyone have the code to display the pictures on the Form only by passing the horse picture names as parameters when I call the subprocedure in the mnuViewNext and mnuViewPrevious event handlers?
I set only 2 horse names because I will add 3 names in the add horses event handler later
Thanks
Public Class Form1
Inherits System.Windows.Forms.Form
Dim gstrShortList(4) As String
Dim gintCurrentRecord As Integer
Dim gintNumberOfHorses(4) As Integer
Private Sub DisplayPicture(ByVal intRecord As Integer)
If intRecord < 0 Then
intRecord = 0
End If
If gintNumberOfHorses.IndexOf(gintNumberOfHorses, 0.0) <> -1 Then
If intRecord > gintNumberOfHorses.IndexOf(gintNumberOfHorses, 0.0) - 1 Then
intRecord = gintNumberOfHorses.IndexOf(gintNumberOfHorses, 0.0) - 1
End If
End If
gintCurrentRecord = intRecord
PictureBox1.Image = Image.FromFile(gstrShortList(gintCurrentRecord))
End Sub
Private Function CountHorses() As Integer
Dim intTotalHorses As Integer
Dim intValue As Integer
For Each intValue In gintNumberOfHorses
intTotalHorses += gintNumberOfHorses(intValue)
Next
Return intTotalHorses
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
gstrShortList(0) = "C:\Horse Arabian.jpg"
gstrShortList(1) = "C:\Horse Mustang.jpg"
gintNumberOfHorses(0) = 0
gintNumberOfHorses(1) = 1
End Sub
Private Sub mnuFileHorsePictures_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileHorsePictures.Click
With OpenFileDialog1
With OpenFileDialog1
.Title = "Choose a Picture to Display"
.InitialDirectory = "C:\My HORSES & NICE HORSES Files"
.CheckFileExists = True
.Filter = "Picture files (*.jpg)/*.jpg"
.ShowDialog()
PictureBox1.Image = Image.FromFile(.FileName)
stbInfo.Text = Convert.ToString(CountHorses())
End With
End With
End Sub
Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click
Close()
End Sub
Private Sub mnuViewNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewNext.Click
DisplayPicture(gintCurrentRecord + 1)
End Sub
Private Sub mnuViewPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewPrevious.Click
DisplayPicture(gintCurrentRecord - 1)
End Sub
End Class
![]() |
Similar Threads
- deploy unsigned windows forms control (activex) for intranet use (ASP.NET)
- update time in windows forms (C#)
- System.Windows.Forms.GroupBox..... Help (C#)
- CrystalDecisions.Windows.Forms not found. (VB.NET)
- autoscroll is not a member of Systems.Windows.Forms.Panel (VB.NET)
- About Windows Forms C# .net 2003 (C#)
- Using Windows XP Visual Styles with Controls on Windows Forms (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: How do I limit text char in Combo box?
- Next Thread: MySQL - ASP.NET - Issues....
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account advanced application array basic beginner browser button buttons center click code combo crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic excel exists fade filter forms ftp generatetags html images input insert intel internet listview mobile module monitor net number objects open panel passingparameters pdf picturebox picturebox2 port position print printing problem regex right-to-left save search searchvb.net select serial settings shutdown soap socket sqldatbase sqlserver survey temperature textbox timer timespan transparency trim txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





