vb2005 picturebox的问题

我想用openFileDialog选定一个jpg,gif等文件然后在picturebox显示出来,怎么做?还有怎么显示同一个文件夹内的下一幅图?改为:如何改变pictur... 我想用openFileDialog选定一个jpg,gif等文件然后在picturebox显示出来,怎么做?
还有怎么显示同一个文件夹内的下一幅图?
改为:如何改变picturebox的width和heigth
我邮箱:toheartz@163.com
谢谢
展开
 我来答
摆渡浮桥
2007-06-03 · TA获得超过3629个赞
知道大有可为答主
回答量:1610
采纳率:100%
帮助的人:2221万
展开全部
下面是我为你写的代码。在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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式