窗體上放一個PictureBox,兩個CommandButton,一個FileListBox
成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于做網(wǎng)站、成都網(wǎng)站制作、巴州網(wǎng)絡(luò)推廣、成都小程序開發(fā)、巴州網(wǎng)絡(luò)營銷、巴州企業(yè)策劃、巴州品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供巴州建站搭建服務(wù),24小時服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
Private Sub Command1_Click()
If File1.ListIndex = 0 Then
ShowPic File1.ListCount - 1
Else
ShowPic File1.ListIndex - 1
End If
End Sub
Private Sub Command2_Click()
If File1.ListIndex = File1.ListCount - 1 Then
ShowPic 0
Else
ShowPic File1.ListIndex + 1
End If
End Sub
Private Sub Form_Load()
File1.Visible = False
File1.Pattern = "*.jpg;*.gif" '可以瀏覽的文件類型,使用分號隔開
File1.Path = App.Path '改成你需要瀏覽的目錄,比如"C:\Pic"
If File1.ListCount 1 Then '目錄中圖片在兩張以上可以瀏覽
ShowPic 0
Exit Sub
ElseIf File1.ListCount = 1 Then '目錄中只有一張圖片時只顯示這一張
ShowPic 0
End If
Command1.Enabled = False
Command2.Enabled = False
End Sub
Private Sub ShowPic(Index As Long)
File1.ListIndex = Index
Picture1.Picture = LoadPicture(File1.Path "\" File1.List(Index))
End Sub
如果對您有幫助,請記得采納為滿意答案,謝謝!祝您生活愉快!
vaela
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
‘ 導(dǎo)入圖片按鈕
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FolderBrowserDialog1.Description = "選擇圖片文件夾導(dǎo)入圖片"
FolderBrowserDialog1.ShowDialog()
path = FolderBrowserDialog1.SelectedPath()
If path = "" Then Return
strSrcFile = Dir(path "\*.tif")
PictureBox1.Image = Image.FromFile(path "\" strSrcFile)
dirFiles.Add(path "\" strSrcFile)
FileNames.Add(strSrcFile)
Do
strSrcFile = Dir()
dirFiles.Add(path "\" strSrcFile)
If (strSrcFile IsNot Nothing) Then
FileNames.Add(strSrcFile)
End If
Loop Until Len(strSrcFile) = 0
End Sub
’ 上一張圖片(我做的按鈕,鼠標(biāo)左鍵的話原理也是一樣 的,你放到鼠標(biāo)左鍵事件中就可以了)
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click '向前
If path "" Then
If (saveDirFiles.Count = 0) Then
Return
End If
MyPos = 0
PictureBox1.Image = Image.FromFile(saveDirFiles(saveDirFiles.Count - 1).ToString())
dirFiles.Insert(0, saveDirFiles(saveDirFiles.Count - 1).ToString())
saveDirFiles.RemoveAt(saveDirFiles.Count - 1)
End If
End Sub
’ 下一張圖片
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click '向后
If path "" Then
If (dirFiles.Count = 0) Then
Return
End If
MyPos = 0
Dim iCurrentPos As Integer = 0
Try
PictureBox1.Image = Image.FromFile(dirFiles(iCurrentPos + 1).ToString())
Catch ex As Exception
MsgBox("已翻至圖片的最后一頁")
Return
End Try
saveDirFiles.Add(dirFiles(iCurrentPos))
dirFiles.RemoveAt(iCurrentPos)
End sub
Public Class Form1
Private TPS As Integer
Private TPPath() As String '定義不確定元素個數(shù)組,及動態(tài)數(shù)組
Private Sub LoadPhoto()
'將圖片路徑及圖片名加載到數(shù)組
Dim JS As Integer '計數(shù)用
For Each foundFile As String In My.Computer.FileSystem.GetFiles(CurDir() "\職員圖片")
TPS = TPS + 1 '將圖片數(shù)存入變量中
Next
ReDim TPPath(TPS - 1) '確定數(shù)組大小
For Each FoundFile As String In My.Computer.FileSystem.GetFiles(CurDir() "\職員圖片")
'將圖片路徑存入數(shù)組
TPPath(JS) = FoundFile
JS = JS + 1
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadPhoto()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = TPPath.Length '獲取數(shù)組大小
Label1.Text = TPPath(1) '獲取數(shù)組中第2個元素的值
End Sub
我說選把打開多個圖片路徑加載到一個listbox里,利用listbox寫代碼
Private Sub picbox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If ListBox1.SelectedIndex = count Then
Try
ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
Catch
ListBox1.SelectedIndex = 0
End Try
End If
picbox.Image = ListBox1.SelectedItem.ToString
End Sub
轉(zhuǎn)換成位圖肯定是可以瀏覽的,WMF文件沒試過。
你可以將圖片以二進(jìn)制形式存儲在數(shù)據(jù)庫中,如果是SQL Server,對應(yīng)字段的類型應(yīng)該是image。