用VB.NET制作图片浏览器时 ,打开图片文件时只能一张一张的打开,如何设置可以一次打开多个图片文件

如题所述

第1个回答  2013-05-19
Public Class Form1
Dim Files() As String
Dim ImgNum As Integer = 0
Dim CurIdx As Integer = 0

Sub OpenFiles()
InitialSet()
Try
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
If Not OpenFileDialog1.FileNames Is Nothing Then
Files = OpenFileDialog1.FileNames
Else
Files(0) = OpenFileDialog1.FileName
End If
ImgNum = Files.Length
Dim s As String = String.Format("你共打开 {0} 张图片", ImgNum)
Me.Text = s
StateSet()
CurIdx = 1
DisplayImage(CurIdx)
Else
StateSet()
Me.PictureBox1.Image = Nothing
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Sub InitialSet()
Me.OpenFileDialog1.Multiselect = True
Me.OpenFileDialog1.Filter = "(*.jpg)|*jpg"
Me.OpenFileDialog1.FilterIndex = 0
ImgNum = 0
CurIdx = 0
If Not Files Is Nothing Then
Array.Clear(Files, 0, Files.Length - 1)
End If
End Sub
Sub DisplayImage(ByRef Idx As Integer)
If IO.Path.GetExtension(Files(Idx - 1)).ToLower = ".jpg" Then
Me.PictureBox1.Load(Files(Idx - 1))
End If
StateSet()
End Sub
Sub StateSet()
If ImgNum > 1 Then
Me.btnNext.Enabled = True
Else
Me.btnNext.Enabled = False
Me.btnPervious.Enabled = False
Exit Sub
End If
If CurIdx > 1 And ImgNum > 1 Then
Me.btnPervious.Enabled = True
Else
Me.btnPervious.Enabled = False
End If
If CurIdx < ImgNum And ImgNum > 1 Then
Me.btnNext.Enabled = True
Else
Me.btnNext.Enabled = False
End If
End Sub

Sub NextIamge(ByRef Idx As Integer)

If Idx < ImgNum Then
Idx += 1
Else
Exit Sub
End If
DisplayImage(Idx)

End Sub
Sub PerviousIagme(ByRef Idx As Integer)
If Idx <> 1 Then
Idx -= 1
Else
Exit Sub
End If
DisplayImage(Idx)

End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Try
NextIamge(CurIdx)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
OpenFiles()
End Sub
Private Sub btnPervious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPervious.Click
Try
PerviousIagme(CurIdx)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
第2个回答  2013-05-15
获取文件夹路径,用For Each获取文件夹路径下的文件数,然后用For Each循环获取jpg|bmp|gif|png格式的路径,循环新建PictureBox,设置图片大小,路径,控件的间隔。我基本用的就是这样的方法,代码就不用上了吧

vb.net 怎么来回切换图片?
vb.net 怎么来回切换图片?1、添加控件Picturebox1和控件Timer1,将Timer1的Interval属性改为1000(即1秒),Enabled属性改为True 2、假设你要循环切换4张图片,你可以添加如下代码即可实现:Dim a As Integer = 0 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventAr...

我要做一个用vb编写的图片浏览器,怎样使用定时器控件使其每间隔1000毫秒...
作用:把我的文档中图片文档的所有jpe和gif图片加载到ListBox控件中,然后Timer控件就每隔一秒读取ListBox中的图片路径文件名列表显示到PictureBox上。代码:Public Class Form1 Dim PicIndex As Long Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me...

手机不能连续察看图片,只能一张一张打开。有什么办法解决吗
看样子有点象高仿机,高仿机就是关掉一张图片才可看另外一张的。如果是真的诺基亚在图片文件夹里面按上下键就可以连续看了。

求大神指点vb.net 怎么以指定方式打开图片呢?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '建立新的系统进程 Dim process As New System.Diagnostics.Process() If RadioButton1.Checked Then '设置文件名,此处为图片的真实路径+文件名 process.StartInfo.FileName = "c:\\a.bmp" '...

如何通过vb.net或者C#把多张小图片合并成一张大图片
用GDI 先建一个6400*4800的Image 类的位图图像 作为GDI画板 然后用Drawimage方法,加载小图像,并按坐标位置画进去 然后保存成文件 我有一个相似功能的VB.net代码,可以给你参考

VB.Net 如何用代码为picturebox 打开一张图片
Dim fn As String = "D:\\test.jpg" '方法1 Me.PictureBox1.ImageLocation = fn '方法2 Me.PictureBox1.Image = Image.FromFile(fn)

VB.net如何设置程序运行时最先打开的窗体?
你是不是用的Visual Studio来开发的?如果是,这样操作:打开 项目 菜单 中的 XXX属性,在弹出的属性页选择最上面那个 应用程序 标签,里面有个启动窗体,你选择一下就可以了。如果你不是用的visual Studio来开发的,那么可以考虑把另外一个窗口的visible属性先设置为false或者把你要显示的窗口改为对话...

vb制作的屏保系统,由多张图片循环播放,如何在图片播放时加上一定的...
'这个拿去试一试,两个时钟,两个图片框,自己设定图片框2的大小,比如让它和窗体一样大 '查一查PaintPicture的用法,就明白了 '去掉Picture2 Dim Pic_num As Long Dim Pic_name() As String Dim pic_star As Long Dim p_width As Single Dim p_height As Single Dim bili_w As Single Dim ...

vb.net保存图片时如何调整其分辨率
保存前加一句 myImage2.SetResolution(300, 300) 你设置的bMape不是保存的主画布 所以无效,设置分辨率就是 SetResolution(X,Y)

在VB.NET开发程序时,如何设置一个欢迎界面?
很好做啊,另外做一个界面,borderstyle=0,里面可以放一张图片什么的。再利用timer控件控制显示的时间。Private i As Integer Private Sub Form_Load()i = 5 ''假设5秒关闭 Timer1.Interval = 1000 ''间隔1秒 Form2.Show vbModal ''显示欢迎窗口 End Sub Private Sub Timer1_Timer()...

相似回答