Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Please Select a File"
OpenFileDialog1.InitialDirectory = "C:temp"
OpenFileDialog1.ShowDialog(PictureBox1)
Button1.Visible = True
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Button2.Visible = True
Application.Exit()
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
PictureBox1.Text = OpenFileDialog1.FileName.ToString()
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
End Class
6 Replies - 334 Views - Last Post: 31 January 2013 - 11:34 PM
#1
How to display a picture in a picturebox from a file on PC
Posted 21 January 2013 - 09:57 PM
I'm trying to make a Picture viewer in Visual Basic 2012 and I can't get it display in the picturebox
Replies To: How to display a picture in a picturebox from a file on PC
#2
Re: How to display a picture in a picturebox from a file on PC
Posted 21 January 2013 - 10:02 PM
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.PictureBox1.BackgroundImage = Image.FromFile("C:\Documents and Settings\kai\My Documents\My Pictures\d1.jpg")
End Sub
D1 is the name of picture to be displayed
This post has been edited by kai_itz me: 21 January 2013 - 10:03 PM
#3
Re: How to display a picture in a picturebox from a file on PC
Posted 21 January 2013 - 10:10 PM
kai_itz me, on 21 January 2013 - 10:02 PM, said:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.PictureBox1.BackgroundImage = Image.FromFile("C:\Documents and Settings\kai\My Documents\My Pictures\d1.jpg")
End Sub
D1 is the name of picture to be displayed
I'm trying to use the OpenFileDialog command, so the user selects a picture from their Computer and the program displays it
#4
Re: How to display a picture in a picturebox from a file on PC
Posted 21 January 2013 - 10:29 PM
in the picturebox1 properties u can set backgroundimagelayout to strech.
this will show full image
this will show full image
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Please Select a File"
OpenFileDialog1.InitialDirectory = "C:temp"
OpenFileDialog1.ShowDialog(PictureBox1)
Me.PictureBox1.BackgroundImage = Image.FromFile("C:\Documents and Settings\kai\My Documents\My Pictures\d1.jpg")
PictureBox1.Visible = True
Button1.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
PictureBox1.Text = OpenFileDialog1.FileName.ToString()
End Sub
End Class
#5
Re: How to display a picture in a picturebox from a file on PC
Posted 21 January 2013 - 11:00 PM
kai_itz me, on 21 January 2013 - 10:29 PM, said:
in the picturebox1 properties u can set backgroundimagelayout to strech.
this will show full image
this will show full image
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Please Select a File"
OpenFileDialog1.InitialDirectory = "C:temp"
OpenFileDialog1.ShowDialog(PictureBox1)
Me.PictureBox1.BackgroundImage = Image.FromFile("C:\Documents and Settings\kai\My Documents\My Pictures\d1.jpg")
PictureBox1.Visible = True
Button1.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
PictureBox1.Text = OpenFileDialog1.FileName.ToString()
End Sub
End Class
Thanks that worked
#6
Re: How to display a picture in a picturebox from a file on PC
Posted 21 January 2013 - 11:30 PM
the above will show only a particular file...(sorry i missread)
i have corrected this
the below code will show the selected file from a particular location.
i have corrected this
the below code will show the selected file from a particular location.
Dim img As String
Public Sub OpenImage()
'Set the Filter.
OpenFileDialog1.Filter = "Bitmap |*.bmp| JPG | *.jpg | GIF | *.gif | All Files|*.*"
'Clear the file name
OpenFileDialog1.FileName = ""
'Show it
If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
'Get the image name
img = OpenFileDialog1.FileName
'Create a new Bitmap and display it
PictureBox1.Image = System.Drawing.Bitmap.FromFile(img)
End If
End Sub
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Visible = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenImage()
End Sub
This post has been edited by kai_itz me: 21 January 2013 - 11:37 PM
#7
Re: How to display a picture in a picturebox from a file on PC
Posted 31 January 2013 - 11:34 PM
jnova, please read http://www.dreaminco...his-is-old-vb6/ .
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|