Berikut ini saya akan bagikan source code untuk Menampilkan Gambar/Image Visual Basic, mudah-mudahan dapat membantu bagi penggemar programing visual basic. Source code ini hanya sederhana dan anda bisa kembangkan sesuai kebutuhan.
Tampilannya seperti gambar berikut:
Tampilannya seperti gambar berikut:
Dalam source kode diatas ada fungsi menampilkan data dengan memilih drive. berikut source codenya:
Option Explicit
Private Sub Form_Load()
Drive1.Drive = "c:"
Dir1.Path = "c:\windows"
File1.Pattern = "*.bmp;*.dib;*.wmf;*.emf;*.gif;*.jpg"
End Sub
Private Sub Drive1_Change()
Dir1.Path = Left$(Drive1.Drive, 1) & ":\"
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub File1_Click()
LoadImage File1.Path & IIf(Right$(File1.Path, 1) <> "\", "\", "") & File1.filename
End Sub
Private Sub Form_Resize()
On Error Resume Next
File1.Height = ScaleHeight - File1.Top
picPreview.Move picPreview.Left, picPreview.Top, ScaleWidth - picPreview.Left, ScaleHeight - picPreview.Top
ShowImage
End Sub
Private Sub optActual_Click()
ShowImage
End Sub
Private Sub optStretch_Click()
ShowImage
End Sub
Private Sub optTile_Click()
ShowImage
End Sub
Sub LoadImage(filename As String)
On Error Resume Next
Set imgHidden.Picture = LoadPicture(filename)
If Err Then
MsgBox "Unable to load file " & filename, vbExclamation
Exit Sub
End If
Caption = filename & "- Image Preview"
ShowImage
End Sub
Sub ShowImage()
Dim x As Single, y As Single
If optActual.Value Then
' Tampilan image center
picPreview.Cls
picPreview.PaintPicture imgHidden.Picture, (picPreview.ScaleWidth - imgHidden.Width) / 2, (picPreview.ScaleHeight - imgHidden.Height) / 2
ElseIf optStretch.Value Then
' Tampilan image stretch
picPreview.PaintPicture imgHidden.Picture, 0, 0, picPreview.ScaleWidth, picPreview.ScaleHeight
ElseIf optTile.Value Then
' Tampilan image actual
x = 0
Do While x < picPreview.ScaleWidth
y = 0
Do While y < picPreview.ScaleHeight
picPreview.PaintPicture imgHidden.Picture, x, y
y = y + imgHidden.Height
Loop
x = x + imgHidden.Width
Loop
End If
End Sub
Private Sub Form_Load()
Drive1.Drive = "c:"
Dir1.Path = "c:\windows"
File1.Pattern = "*.bmp;*.dib;*.wmf;*.emf;*.gif;*.jpg"
End Sub
Private Sub Drive1_Change()
Dir1.Path = Left$(Drive1.Drive, 1) & ":\"
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub File1_Click()
LoadImage File1.Path & IIf(Right$(File1.Path, 1) <> "\", "\", "") & File1.filename
End Sub
Private Sub Form_Resize()
On Error Resume Next
File1.Height = ScaleHeight - File1.Top
picPreview.Move picPreview.Left, picPreview.Top, ScaleWidth - picPreview.Left, ScaleHeight - picPreview.Top
ShowImage
End Sub
Private Sub optActual_Click()
ShowImage
End Sub
Private Sub optStretch_Click()
ShowImage
End Sub
Private Sub optTile_Click()
ShowImage
End Sub
Sub LoadImage(filename As String)
On Error Resume Next
Set imgHidden.Picture = LoadPicture(filename)
If Err Then
MsgBox "Unable to load file " & filename, vbExclamation
Exit Sub
End If
Caption = filename & "- Image Preview"
ShowImage
End Sub
Sub ShowImage()
Dim x As Single, y As Single
If optActual.Value Then
' Tampilan image center
picPreview.Cls
picPreview.PaintPicture imgHidden.Picture, (picPreview.ScaleWidth - imgHidden.Width) / 2, (picPreview.ScaleHeight - imgHidden.Height) / 2
ElseIf optStretch.Value Then
' Tampilan image stretch
picPreview.PaintPicture imgHidden.Picture, 0, 0, picPreview.ScaleWidth, picPreview.ScaleHeight
ElseIf optTile.Value Then
' Tampilan image actual
x = 0
Do While x < picPreview.ScaleWidth
y = 0
Do While y < picPreview.ScaleHeight
picPreview.PaintPicture imgHidden.Picture, x, y
y = y + imgHidden.Height
Loop
x = x + imgHidden.Width
Loop
End If
End Sub
Demikian sample source code Menampilkan Gambar/Image VB apabila masih ada kekurangan mohon dimaafkan. Source code Download
0 komentar:
Komentar Anda
Berikan komentar..