vb2005 picturebox的问题
我想用openFileDialog选定一个jpg,gif等文件然后在picturebox显示出来,怎么做?还有怎么显示同一个文件夹内的下一幅图?改为:如何改变pictur...
我想用openFileDialog选定一个jpg,gif等文件然后在picturebox显示出来,怎么做?
还有怎么显示同一个文件夹内的下一幅图?
改为:如何改变picturebox的width和heigth
我邮箱:toheartz@163.com
谢谢 展开
还有怎么显示同一个文件夹内的下一幅图?
改为:如何改变picturebox的width和heigth
我邮箱:toheartz@163.com
谢谢 展开
展开全部
下面是我为你写的代码。在form1中添加三个按钮,一个picturebox和一个状态栏。
给个邮箱地址,可以把整个project发给你。
Public Class Form1
Dim PicturePath As String
Dim Files As List(Of String) = New List(Of String)
Dim CurrentPicture As Integer
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
Dim result As DialogResult
result = OpenFileDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.Cancel Then
Exit Sub
End If
Try
Dim aPicture As Bitmap = New Bitmap(OpenFileDialog1.FileName)
PictureBox1.Image = CType(aPicture, Image)
Dim index As Integer = OpenFileDialog1.FileName.LastIndexOf("\")
PicturePath = OpenFileDialog1.FileName.Substring(0, index)
Files.Clear()
CurrentPicture = 0
For Each file As String In My.Computer.FileSystem.GetFiles(PicturePath)
If file.ToUpper.EndsWith(".JPG") OrElse file.ToUpper.EndsWith(".GIF") Then
Files.Add(file)
End If
Next
Catch ex As Exception
End Try
End Sub
Private Sub LoadPicture(ByVal PictureFile As String)
Dim aPicture As Bitmap = New Bitmap(PictureFile)
PictureBox1.Image = CType(aPicture, Image)
StatusLabel1.Text = PictureFile
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If CurrentPicture >= Files.Count - 1 OrElse CurrentPicture < 0 _
OrElse Files.Count = 0 Then
Exit Sub
End If
CurrentPicture += 1
LoadPicture(Files(CurrentPicture))
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
If CurrentPicture > Files.Count - 1 OrElse CurrentPicture < 1 OrElse Files.Count = 0 Then
Exit Sub
End If
CurrentPicture -= 1
LoadPicture(Files(CurrentPicture))
End Sub
End Class
给个邮箱地址,可以把整个project发给你。
Public Class Form1
Dim PicturePath As String
Dim Files As List(Of String) = New List(Of String)
Dim CurrentPicture As Integer
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
Dim result As DialogResult
result = OpenFileDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.Cancel Then
Exit Sub
End If
Try
Dim aPicture As Bitmap = New Bitmap(OpenFileDialog1.FileName)
PictureBox1.Image = CType(aPicture, Image)
Dim index As Integer = OpenFileDialog1.FileName.LastIndexOf("\")
PicturePath = OpenFileDialog1.FileName.Substring(0, index)
Files.Clear()
CurrentPicture = 0
For Each file As String In My.Computer.FileSystem.GetFiles(PicturePath)
If file.ToUpper.EndsWith(".JPG") OrElse file.ToUpper.EndsWith(".GIF") Then
Files.Add(file)
End If
Next
Catch ex As Exception
End Try
End Sub
Private Sub LoadPicture(ByVal PictureFile As String)
Dim aPicture As Bitmap = New Bitmap(PictureFile)
PictureBox1.Image = CType(aPicture, Image)
StatusLabel1.Text = PictureFile
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If CurrentPicture >= Files.Count - 1 OrElse CurrentPicture < 0 _
OrElse Files.Count = 0 Then
Exit Sub
End If
CurrentPicture += 1
LoadPicture(Files(CurrentPicture))
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
If CurrentPicture > Files.Count - 1 OrElse CurrentPicture < 1 OrElse Files.Count = 0 Then
Exit Sub
End If
CurrentPicture -= 1
LoadPicture(Files(CurrentPicture))
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询