Results 1 to 1 of 1

Thread: code: form bumping at screen sides

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Location
    Porsgrunn,NORWAY
    Posts
    30

    code: form bumping at screen sides

    CREATE A MODULE WITH THIS CODE:
    Private Type mform
    X As Long
    Y As Long
    XWay As Long
    YWay As Long
    End Type

    Global Form As mform

    THEN PASTE THIS INTO YOUR FORM:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Unload Me
    End
    End Sub

    Private Sub Form_Load()
    SetProp
    Main
    End Sub

    Sub SetProp()
    Me.Show
    Me.ScaleMode = vbPixels
    Me.Left = Screen.Width / 3
    Me.Top = Screen.Height / 3
    Form.XWay = 1
    Form.YWay = 1

    Form.X = Screen.Width / 3
    Form.Y = Screen.Height / 3
    End Sub

    Sub Main()
    Do
    Form.X = Form.X + Form.XWay
    Form.Y = Form.Y + Form.YWay
    Me.Left = Form.X
    Me.Top = Form.Y

    Select Case Form.X
    Case Is < 0
    Form.X = 0
    Form.XWay = -Form.XWay
    Case Is > Screen.Width - Me.Width
    Form.X = Screen.Width - Me.Width
    Form.XWay = -Form.XWay
    End Select

    Select Case Form.Y
    Case Is < 0
    Form.Y = 0
    Form.YWay = -Form.YWay
    Case Is > Screen.Height - Me.Height
    Form.Y = Screen.Height - Me.Height
    Form.YWay = -Form.YWay
    End Select

    DoEvents
    Loop
    End Sub
    Last edited by Kennethj; Apr 9th, 2002 at 07:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width