Results 1 to 7 of 7

Thread: Always on Screen

  1. #1

    Thread Starter
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    how do I make the form always on the screen? so like if i move it to the edge, it wont go over the edge. like a PayForSurf Bar

  2. #2
    Guest
    Here you go:

    Code:
    Public Declare Sub ReleaseCapture Lib "user32" ()
    
    Public Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
    Long, ByVal wParam As Long, lParam As Any) As Long
    
    
    Public Sub FormMove(frm As Form)
        ReleaseCapture
        SendMessage frm.hwnd, &H112, &HF012, 0
        If frm.Left < 0 Then 'left side of screen
            frm.Left = 0
                If frm.Top < 0 Then
                    frm.Top = 0
                ElseIf frm.Top > Screen.Height - frm.Height Then
                    frm.Top = Screen.Height - frm.Height
                End If
        ElseIf frm.Top < 0 Then 'top of screen
            frm.Top = 0
                If frm.Left < 0 Then
                    frm.Top = 0
                ElseIf frm.Left > Screen.Width - frm.Width Then
                    frm.Left = Screen.Width - frm.Width
                End If
        ElseIf frm.Left > Screen.Width - frm.Width Then 'right of screen
           frm.Left = Screen.Width - frm.Width
                If frm.Top < 0 Then
                    frm.Top = 0
                ElseIf frm.Top > Screen.Height - frm.Height Then
                    frm.Top = Screen.Height - frm.Height
                End If
        ElseIf frm.Top > Screen.Height - frm.Height Then 'bottom of screen
            frm.Top = Screen.Height - frm.Height
                If frm.Left < 0 Then
                    frm.Top = 0
                ElseIf frm.Left > Screen.Width - frm.Width Then
                    frm.Left = Screen.Width - frm.Width
                End If
        End If
    End Sub
    
    
    Usage
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Call FormMove(Me)
    End Sub
    [Edited by Matthew Gates on 11-13-2000 at 07:18 PM]

  3. #3

    Thread Starter
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    thanx ill try that
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  4. #4
    Guest
    If you don't want to use a Module, change Public to Private.

    Code:
    Private Declare Sub ReleaseCapture Lib "user32" ()
    
    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
    Long, ByVal wParam As Long, lParam As Any) As Long
    
    
    Private Sub FormMove(frm As Form)
        ReleaseCapture
        SendMessage frm.hwnd, &H112, &HF012, 0
        If frm.Left < 0 Then 'left side of screen
            frm.Left = 0
                If frm.Top < 0 Then
                    frm.Top = 0
                ElseIf frm.Top > Screen.Height - frm.Height Then
                    frm.Top = Screen.Height - frm.Height
                End If
        ElseIf frm.Top < 0 Then 'top of screen
            frm.Top = 0
                If frm.Left < 0 Then
                    frm.Top = 0
                ElseIf frm.Left > Screen.Width - frm.Width Then
                    frm.Left = Screen.Width - frm.Width
                End If
        ElseIf frm.Left > Screen.Width - frm.Width Then 'right of screen
           frm.Left = Screen.Width - frm.Width
                If frm.Top < 0 Then
                    frm.Top = 0
                ElseIf frm.Top > Screen.Height - frm.Height Then
                    frm.Top = Screen.Height - frm.Height
                End If
        ElseIf frm.Top > Screen.Height - frm.Height Then 'bottom of screen
            frm.Top = Screen.Height - frm.Height
                If frm.Left < 0 Then
                    frm.Top = 0
                ElseIf frm.Left > Screen.Width - frm.Width Then
                    frm.Left = Screen.Width - frm.Width
                End If
        End If
    End Sub
    
    
    Usage
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Call FormMove(Me)
    End Sub

  5. #5

    Thread Starter
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    doesnt work. what am i doing wrong
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  6. #6
    Guest
    When you let go of the mouse, it snaps back into place.

  7. #7

    Thread Starter
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    oh. okay thanx
    Remember, if someone's post was not helpful, you can always rate their post negatively .

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