17 August 2012

Cara membuat form tampil di pojok kanan bawah

Sering kali kita melihat dan berfikir bagaimana cara kita supaya form kita otomatis tampil di bagian pojok kanan tepatnya di bagian bawah tanpa harus di tata letaknya .


Nah, itulah yang akan kita bahas pada hari ini .
langkah pertama buat sebuah form dengan 1 command button, dan 3 buah timer ..
tapi timer2 nya ber enable False ..
Timer1 dan timer2 berInterval   = 50
dan timer3 nya ber Interval = 15000
masukkan code ini ke dalam form :



Const n = vbNewLine
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cX As Long, ByVal cY As Long, ByVal wFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags 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

' Flag to Prevent further Loading of form when it is already on memory
Private Loaded As Boolean


' Transparency Constants
Const LWA_COLORKEY = &H3
Const LWA_ALPHA = &H3
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Private Const HWND_TOPMOST = -1
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOOWNERZORDER = &H200
Dim ret As Long

'Form Unloading Area


Private Sub Command1_Click()
'set that the form was  loaded once
Loaded = True
'enable the Timer to hide the form
Timer2.Enabled = True
End Sub

Private Sub Form_Load()
'Get the Picture
'Image2.Picture = LoadPicture(App.Path & "\error.gif")

'Set The Position of the form
Me.Top = Screen.Height
Me.Left = Screen.Width - Me.Width


'Check if The form had been loaded , if loaded then unload it
If Loaded Then Unload Me: Loaded = False Else Loaded = True
End Sub

'This sub calculates the total height necessary for the form
'This sub resizes the form according to the message. This should me called before
'-the form is shown
Public Sub Resize()
Me.Height = Me.Height + Label2.Height
Command1.Top = Me.Height - 500 '+ Label2.Height - 500
End Sub


Private Sub Form_Terminate()
Unload Me 'unload the form
End Sub

'Slide the form into view
Private Sub Timer1_Timer()
'Check if the form has reached its maximum height & if Yes then stop timer
If Me.Top <= Screen.Height - (Me.Height + 250) Then Timer1.Enabled = False

'else Move it position to 100 pix top
Me.Top = Me.Top - 100
End Sub

 'Hide the form by scroll method ( same as above)
 Public Sub Delete()

 End Sub

 'Scroll out timer
Private Sub Timer2_Timer()
On Error Resume Next ' Will raise an error if the form is unloaded unexpectedly
'so keep an error trapper

'Check if the form has reached its minimum height & if Yes then stop timer
If Me.Top >= 11000 Then
Timer2.Enabled = False
'Unload the form
Unload Me
End If

'else Move it position to 100 pix down
Me.Top = Me.Top + 100
End Sub


'Time out Timer
'Automatically close the box after 20 secs.
Private Sub Timer3_Timer()

'Enable Scroll out timer
Timer2.Enabled = True

'Disable this timer
Timer3.Enabled = False

End Sub
Nah, Selesai deh ..
Semoga bermanfaat ....




7 comments:

  1. ok bagus
    terima kasih udah nemuin solusinya

    ReplyDelete
  2. artikel bermanfaat gan , cuman saran gan ente pasang link >> donasi beserta no. rekening siapa tau ada yang ngasih fee :D

    ReplyDelete
  3. Saran yang bagus banget tuh gan, makasiih atas sarannya .

    ReplyDelete
  4. makasih ilmu nya salam kenal gan kunjung balik bro www.yboot.blogspot.com

    ReplyDelete

Recent Comment

Contact Form

Name

Email *

Message *

2012 © Jabat Software