Trik di visual basic
Assalammualaikum. . .sekedar mau berbagi aja nih... walaupun saya jg blum bs apa2... semoga bisa membantu teman2 disana...
1. Karakter Password (*)
2. Center Screen ( meletakkan form di tengah )
Seringkali jika aplikasi Anda dijalankan, letak form aplikasi tersebut pada layar monitor tidak menetap. Kadang di kiri atas, kadang di tengah, kadang di bawah. Bagi Anda yang menyukai kerapian, mungkin hal ini akan terasa menjengkelkan. Ada suatu trik mudah agar form aplikasi tersebut selalu terletak di tengah layar monitor jika dieksekusi, yaitu dengan mengubah properti StartUpPosition menjadi 2 – CenterScreen.
3. Menambahkan Gambar pada Command button
4. Mengatur Letak Form (diTengah / diKiri / diKanan )
5. Membuat Efek Ledakan di Form
Membuat suatu efek ledakan pada pemunculan awal suatu form.
Persiapan:
1. Buat 1 Project baru dengan 1 Form dan 1 Module, dan 1 Commandbutton.
2. Copy-kan coding berikut ke dalam editor Module.
#If Win16 Then
Type RECT
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type
#Else
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
#End If
#If Win16 Then
Declare Sub GetWindowRect Lib "User" (ByVal hwnd As Integer, lpRect As RECT)
Declare Function GetDC Lib "User" (ByVal hwnd As Integer) As Integer
Declare Function ReleaseDC Lib "User" (ByVal hwnd As Integer, ByVal hdc As _
Integer) As Integer
Declare Sub SetBkColor Lib "GDI" (ByVal hdc As Integer, ByVal crColor As Long)
Declare Sub Rectangle Lib "GDI" (ByVal hdc As Integer, ByVal X1 As Integer, _
ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer)
Declare Function CreateSolidBrush Lib "GDI" (ByVal crColor As Long) As Integer
Declare Function SelectObject Lib "GDI" (ByVal hdc As Integer, ByVal hObject _
As Integer) As Integer
Declare Sub DeleteObject Lib "GDI" (ByVal hObject As Integer)
#Else
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, _
lpRect As RECT) As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal _
hdc As Long) As Long
Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal _
crColor As Long) As Long
Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Declare Function SelectObject Lib "user32" (ByVal hdc As Long, ByVal hObject _
As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
#End If
Sub ExplodeForm(f As Form, Movement As Integer)
Dim myRect As RECT
Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%
Dim TheScreen As Long
Dim Brush As Long
GetWindowRect f.hwnd, myRect
formWidth = (myRect.Right - myRect.Left)
formHeight = myRect.Bottom - myRect.Top
TheScreen = GetDC(0)
Brush = CreateSolidBrush(f.BackColor)
For i = 1 To Movement
Cx = formWidth * (i / Movement)
Cy = formHeight * (i / Movement)
X = myRect.Left + (formWidth - Cx) / 2
Y = myRect.Top + (formHeight - Cy) / 2
Rectangle TheScreen, X, Y, X + Cx, Y + Cy
Next i
X = ReleaseDC(0, TheScreen)
DeleteObject (Brush)
End Sub
Public Sub ImplodeForm(f As Form, Movement As Integer)
Dim myRect As RECT
Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%
Dim TheScreen As Long
Dim Brush As Long
GetWindowRect f.hwnd, myRect
formWidth = (myRect.Right - myRect.Left)
formHeight = myRect.Bottom - myRect.Top
TheScreen = GetDC(0)
Brush = CreateSolidBrush(f.BackColor)
For i = Movement To 1 Step -1
Cx = formWidth * (i / Movement)
Cy = formHeight * (i / Movement)
X = myRect.Left + (formWidth - Cx) / 2
Y = myRect.Top + (formHeight - Cy) / 2
Rectangle TheScreen, X, Y, X + Cx, Y + Cy
Next i
X = ReleaseDC(0, TheScreen)
DeleteObject (Brush)
End Sub
dan ini untuk listing di form-nya .
Private Sub Command1_Click()
'Ganti '500' di bawah dengan kecepatan dari efek ledakan form.
Call ImplodeForm(Me, 500)
End
Set Form1 = Nothing
End Sub
Private Sub Form_Load()
Call ExplodeForm(Me, 500) 'ledakan form
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call ImplodeForm(Me, 500) 'pengembalian form
End Sub
6. Membuat Efek Vibrate atau getar pada form
7. Membuat Aminasi Form Exit
Bagi yang tertarik dengan animasi silahkan Copas coding dibawah ini.
Persiapan:
1. Buat 1 Project baru dengan 1 Form dan 1 Commandbutton.
atau
langsung di copas di commandbutton-nya.
8. Membuat Form ransparan
9. Menambahkan Gambar dengan format .Gif di form
4. Lihat ditoolboxnya sudah tampil belum komponen barunya bernama anigif
5.klik anigif darg ke form vb
6. Buka coding ketikan di form - load :
animatedgif1.loadfile app.path +"\gambar.gif",false => Jika dalam satu folder
animatedgif.loadfile "c:\mydocuments\gambar.gif",false => Jika tidak dalam satu folder
7. Klik Run
Jika error perhatikan alamat gambar sama nama gambar .gif
Alhamdulillah... mudah-mudahan ada mamfaat nya bagi kita semua dan khusus nya bagi para pecinta VB atau rekan-rekan yg sedang mengerjakan TA... semoga dapat menambah referensinya, sebelumnya terimakasih buat sobat-sobat yang sudah sudi mengkomentari artikel ini ... salam.
1. Karakter Password (*)
Anda tentu sudah mengetahui bahwa pada aplikasi tertentu yang menggunakan password, text box yang digunakan untuk mengisi password selalu memunculkan karakter bintang (*) jika Anda mengetikkan sesuatu ke dalamnya. Hal ini tentu saja dimaksudkan agar orang lain tidak dapat membaca karakter sebenarnya yang Anda ketikkan. Untuk membuat sebuah text box agar mengeluarkan karakter * (atau bahkan karakter yang lain) caranya sangat mudah, yaitu mengisikan karakter yang Anda inginkan pada properti PasswordChar kontrol text box. Setelah itu jika Anda mengetikkan sesuatu ke dalam text box tersebut, maka karakter yang akan muncul adalah karakter yang Anda masukkan ke dalam properti PasswordChar tersebut.
2. Center Screen ( meletakkan form di tengah )
3. Menambahkan Gambar pada Command button
Selama ini Anda selalu menggunakan Caption pada Command Button. Anda juga dapat menambahkan gambar pada Command Button untuk menambah daya tarik aplikasi Anda. Untuk itu ada beberapa properti yang perlu diubah, yaitu:
Properti | Nilai |
Style | 2 - Graphical |
Caption | [Anda boleh mengosongkan properti ini] |
Picture | [Gambar yang hendak ditambahkan pada Command Button] |
DownPicture | [Gambar pada Command Button ketika diklik] |
4. Mengatur Letak Form (diTengah / diKiri / diKanan )
Persiapan:
1. Buat 1 Project baru dengan 1 Form dan 3 Commandbutton.
2. Copy-kan coding berikut ke dalam editor form yang bertalian.
1. Buat 1 Project baru dengan 1 Form dan 3 Commandbutton.
2. Copy-kan coding berikut ke dalam editor form yang bertalian.
Private Sub Command1_Click() 'Kiri
Me.Left = 0
Me.Top = Screen.Height / 2 - Me.Height / 2
End Sub
Private Sub Command2_Click() 'Tengah
Me.Left = Screen.Width / 2 - Me.Width / 2
Me.Top = Screen.Height / 2 - Me.Height / 2
End Sub
Private Sub Command3_Click() 'Kanan
Me.Left = Screen.Width - Me.Width
Me.Top = Screen.Height / 2 - Me.Height / 2
End Sub
Me.Left = 0
Me.Top = Screen.Height / 2 - Me.Height / 2
End Sub
Private Sub Command2_Click() 'Tengah
Me.Left = Screen.Width / 2 - Me.Width / 2
Me.Top = Screen.Height / 2 - Me.Height / 2
End Sub
Private Sub Command3_Click() 'Kanan
Me.Left = Screen.Width - Me.Width
Me.Top = Screen.Height / 2 - Me.Height / 2
End Sub
5. Membuat Efek Ledakan di Form
Persiapan:
1. Buat 1 Project baru dengan 1 Form dan 1 Module, dan 1 Commandbutton.
2. Copy-kan coding berikut ke dalam editor Module.
Type RECT
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type
#Else
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
#End If
#If Win16 Then
Declare Sub GetWindowRect Lib "User" (ByVal hwnd As Integer, lpRect As RECT)
Declare Function GetDC Lib "User" (ByVal hwnd As Integer) As Integer
Declare Function ReleaseDC Lib "User" (ByVal hwnd As Integer, ByVal hdc As _
Integer) As Integer
Declare Sub SetBkColor Lib "GDI" (ByVal hdc As Integer, ByVal crColor As Long)
Declare Sub Rectangle Lib "GDI" (ByVal hdc As Integer, ByVal X1 As Integer, _
ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer)
Declare Function CreateSolidBrush Lib "GDI" (ByVal crColor As Long) As Integer
Declare Function SelectObject Lib "GDI" (ByVal hdc As Integer, ByVal hObject _
As Integer) As Integer
Declare Sub DeleteObject Lib "GDI" (ByVal hObject As Integer)
#Else
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, _
lpRect As RECT) As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal _
hdc As Long) As Long
Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal _
crColor As Long) As Long
Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Declare Function SelectObject Lib "user32" (ByVal hdc As Long, ByVal hObject _
As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
#End If
Sub ExplodeForm(f As Form, Movement As Integer)
Dim myRect As RECT
Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%
Dim TheScreen As Long
Dim Brush As Long
GetWindowRect f.hwnd, myRect
formWidth = (myRect.Right - myRect.Left)
formHeight = myRect.Bottom - myRect.Top
TheScreen = GetDC(0)
Brush = CreateSolidBrush(f.BackColor)
For i = 1 To Movement
Cx = formWidth * (i / Movement)
Cy = formHeight * (i / Movement)
X = myRect.Left + (formWidth - Cx) / 2
Y = myRect.Top + (formHeight - Cy) / 2
Rectangle TheScreen, X, Y, X + Cx, Y + Cy
Next i
X = ReleaseDC(0, TheScreen)
DeleteObject (Brush)
End Sub
Public Sub ImplodeForm(f As Form, Movement As Integer)
Dim myRect As RECT
Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%
Dim TheScreen As Long
Dim Brush As Long
GetWindowRect f.hwnd, myRect
formWidth = (myRect.Right - myRect.Left)
formHeight = myRect.Bottom - myRect.Top
TheScreen = GetDC(0)
Brush = CreateSolidBrush(f.BackColor)
For i = Movement To 1 Step -1
Cx = formWidth * (i / Movement)
Cy = formHeight * (i / Movement)
X = myRect.Left + (formWidth - Cx) / 2
Y = myRect.Top + (formHeight - Cy) / 2
Rectangle TheScreen, X, Y, X + Cx, Y + Cy
Next i
X = ReleaseDC(0, TheScreen)
DeleteObject (Brush)
End Sub
dan ini untuk listing di form-nya .
'Ganti '500' di bawah dengan kecepatan dari efek ledakan form.
Call ImplodeForm(Me, 500)
End
Set Form1 = Nothing
End Sub
Private Sub Form_Load()
Call ExplodeForm(Me, 500) 'ledakan form
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call ImplodeForm(Me, 500) 'pengembalian form
End Sub
6. Membuat Efek Vibrate atau getar pada form
Persiapan:
1. Buat 1 Project baru dengan 1 Form
2. dan Copy listing di bawah ini.
Gak panjang kan, nah kalo udah selesai coba sobat jalankan (Run) atau tekan F5 , apa bener form nya bergetar-getar seperti cacing kepanasan ... (wekekeke ....)
1. Buat 1 Project baru dengan 1 Form
2. dan Copy listing di bawah ini.
Private Sub Vibrate(frm As Form, rScale As Integer, Times As Integer)
Dim Lft As Long, Tp As Long
Dim i
Lft = frm.Left
Tp = frm.Top
For i = 1 To Times
frm.Move Lft + Sgn(rScale)
Pause 20
frm.Move Lft + rScale
Pause 20
frm.Move Lft, Tp + Sgn(rScale), frm.Width, frm.Height
Pause 20
frm.Move Lft, Tp + rScale, frm.Width, frm.Height
Pause 20
Next i
End Sub
Private Sub Pause(ms)
Dim secs
Dim g
secs = ms / 1000
g = Timer
Do While Timer - g < secs
DoEvents
Loop
End Sub
Private Sub Form_Activate()
Vibrate Me, 100, 20
End Sub
Dim Lft As Long, Tp As Long
Dim i
Lft = frm.Left
Tp = frm.Top
For i = 1 To Times
frm.Move Lft + Sgn(rScale)
Pause 20
frm.Move Lft + rScale
Pause 20
frm.Move Lft, Tp + Sgn(rScale), frm.Width, frm.Height
Pause 20
frm.Move Lft, Tp + rScale, frm.Width, frm.Height
Pause 20
Next i
End Sub
Private Sub Pause(ms)
Dim secs
Dim g
secs = ms / 1000
g = Timer
Do While Timer - g < secs
DoEvents
Loop
End Sub
Private Sub Form_Activate()
Vibrate Me, 100, 20
End Sub
Gak panjang kan, nah kalo udah selesai coba sobat jalankan (Run) atau tekan F5 , apa bener form nya bergetar-getar seperti cacing kepanasan ... (wekekeke ....)
7. Membuat Aminasi Form Exit
Persiapan:
1. Buat 1 Project baru dengan 1 Form dan 1 Commandbutton.
Private Sub Command1_Click()
ExitLayout
Unload Me
End Sub
Private Sub ExitLayout()
On Error Resume Next
Dim fHeight As Long
Dim fWidth As Long
For fHeight = Me.Height To 1000 Step -1
Me.Height = fHeight
'Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
Next fHeight
If Me.Height = 1000 Then
For fWidth = Me.Width To 1000 Step -2
Me.Width = fWidth
Next fWidth
End If
Me.Refresh
End Sub
ExitLayout
Unload Me
End Sub
Private Sub ExitLayout()
On Error Resume Next
Dim fHeight As Long
Dim fWidth As Long
For fHeight = Me.Height To 1000 Step -1
Me.Height = fHeight
'Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 3
Next fHeight
If Me.Height = 1000 Then
For fWidth = Me.Width To 1000 Step -2
Me.Width = fWidth
Next fWidth
End If
Me.Refresh
End Sub
atau
langsung di copas di commandbutton-nya.
8. Membuat Form ransparan
Persiapan:
1. Buat 1 Project baru dengan 1 Form
Untuk ketajaman transparant sobat bisa menggati Angka - Angka yang berwarna merah dengan angka yang lain (maximal value 255)
1. Buat 1 Project baru dengan 1 Form
Option Explicit
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crColor As Long, ByVal nAlpha As Byte, ByVal dwFlags As Long) As Long
Private Sub Form_Load()
Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED)
Call SetLayeredWindowAttributes(Me.hwnd, RGB(255, 0, 255), 128, LWA_ALPHA Or LWA_COLORKEY)
End Sub
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crColor As Long, ByVal nAlpha As Byte, ByVal dwFlags As Long) As Long
Private Sub Form_Load()
Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED)
Call SetLayeredWindowAttributes(Me.hwnd, RGB(255, 0, 255), 128, LWA_ALPHA Or LWA_COLORKEY)
End Sub
Untuk ketajaman transparant sobat bisa menggati Angka - Angka yang berwarna merah dengan angka yang lain (maximal value 255)
9. Menambahkan Gambar dengan format .Gif di form
Berikut Tips dalam menambah animasi gambar gerak pada Visual Basic 6.0. yang pada dasarnya memanfaatkan gambar gerak yang berektensi .gif. bagaimana caranya ??? yuk ikuti...
Biasanya sebuah gambar gerak .gif jika dimasukan dalam sebuah form vb maka gambar tersebut hanya gambar biasa alias efek geraknya jadi hilang, betul ngga ? nah dengan menambahkan sebuah komponen animatedgif .ocx maka gambar tersebut menjadi gambar gerak yang sesuai dengan yang kita inginkan. percaya deh pasti bisa ... nah sekarang tinggal kita setting cara menambahkan komponent tersebut caranya :
1. Download dulu komponent animatedgif.ocx disini , kemudian simpan dikomputer masing-masing
Biasanya sebuah gambar gerak .gif jika dimasukan dalam sebuah form vb maka gambar tersebut hanya gambar biasa alias efek geraknya jadi hilang, betul ngga ? nah dengan menambahkan sebuah komponen animatedgif .ocx maka gambar tersebut menjadi gambar gerak yang sesuai dengan yang kita inginkan. percaya deh pasti bisa ... nah sekarang tinggal kita setting cara menambahkan komponent tersebut caranya :
1. Download dulu komponent animatedgif.ocx disini , kemudian simpan dikomputer masing-masing
2. Kemudian copy ke system32 di komputer anda, jika lupa klik disini
3. Buka Vbnya klik Project, component, cari animated gif control
3. Buka Vbnya klik Project, component, cari animated gif control
4. Lihat ditoolboxnya sudah tampil belum komponen barunya bernama anigif
5.klik anigif darg ke form vb
6. Buka coding ketikan di form - load :
animatedgif1.loadfile app.path +"\gambar.gif",false => Jika dalam satu folder
animatedgif.loadfile "c:\mydocuments\gambar.gif",false => Jika tidak dalam satu folder
7. Klik Run
Jika error perhatikan alamat gambar sama nama gambar .gif
Alhamdulillah...
Thanks Gan .....