Results 1 to 14 of 14

Thread: [RESOLVED] Is there a way to dock a form to the right side of the users screen regardless of res

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Resolved [RESOLVED] Is there a way to dock a form to the right side of the users screen regardless of res

    Hi there everyone. I am working on a prog that has lots of features for classroom management. The project has more features, but I would like to add a toolbar on the right side of the screen for whatever their resolution is that would have their most used features of the program ready to use. Some teachers use some parts of the management software more than others, and that part is taken care of, but I am not sure how to "dock" a toolbar to the side of the screen. I can get it in the middle, but would anyone know to how do it regardless of the user resolution. I was thinking in the middle of the right side somehow.

    Thank you!!!

  2. #2
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Is there a way to dock a form to the right side of the users screen regardless of

    Well, this code will move it where you want it.
    Not sure what else you need, maybe lock it? Always on top? No Borders?
    Code:
    Private Sub Form_Load()
    Me.Move Screen.Width - Me.Width, (Screen.Height - Me.Height) / 2
    End Sub

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to dock a form to the right side of the users screen regardless of

    That is a good idea. I can set it to no border, as we won't need it. What about locking it so it can't be moved. I'll add features to hide it, but yea lets keep it always on top.

    What I really like is the sort of disappearing sidebar Windows 8 has where it only shows when you move over to the edge of the screen. Can I add that, or would I get sued? lol

    Thanks.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to dock a form to the right side of the users screen regardless of

    Ok, so after playing around. I use this code to position the form, and make it so it is always on top.

    VB Code:
    1. 'Center the dock on the right side middle
    2. Me.Move Screen.Width - Me.Width, (Screen.Height - Me.Height) / 2
    3.  
    4. 'Set form to always on top
    5. ' On Top
    6. Call SetWindowPos(DockBar.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

    What I would like to try to do now is get a mouse hover over event going, so when my toolbar is hidden, a small piece of it is shown, so if the user puts their mouse over the form, it would call a sub. My question is, is there a mouse hover over event where if the mouse is just over the form anywhere (not clicking on anything), just hovering, can it call a sub?

    Thanks.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to dock a form to the right side of the users screen regardless of

    Quote Originally Posted by Justin M View Post
    Ok, so after playing around. I use this code to position the form, and make it so it is always on top.

    VB Code:
    1. 'Center the dock on the right side middle
    2. Me.Move Screen.Width - Me.Width, (Screen.Height - Me.Height) / 2
    3.  
    4. 'Set form to always on top
    5. ' On Top
    6. Call SetWindowPos(DockBar.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

    What I would like to try to do now is get a mouse hover over event going, so when my toolbar is hidden, a small piece of it is shown, so if the user puts their mouse over the form, it would call a sub. My question is, is there a mouse hover over event where if the mouse is just over the form anywhere (not clicking on anything), just hovering, can it call a sub?

    Thanks.
    Ok it turns out mousemove will help with this!

    Example.

    VB Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, _
    2.     Y As Single)
    3. BankButton = LoadPicture(App.Path & "\ResourceFiles\DockHelper\BankButton.bmp")
    4. End Sub
    5.  
    6.  
    7. Private Sub BankButton_MouseMove(Button As Integer, Shift As Integer, _
    8.     X As Single, Y As Single)
    9. BankButton = LoadPicture(App.Path & "\ResourceFiles\DockHelper\BankButtonbig.bmp")
    10. End Sub

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Is there a way to dock a form to the right side of the users screen regardless of

    Make the Form invisible and when you mouse move over it make it visible and when the mouse moves off the Form make it invisible


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Is there a way to dock a form to the right side of the users screen regardless of

    Ok Justin I made you a small example also using getcursorpos to be more precise in its activation (popping in and out). I have included a slow popping in and out function and also the setwindowpos.

    Code:
    Option Explicit
    
    Const All_Flags = &H10 Or &H40 Or &H2 Or &H1
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Enum TopMostEnum
      TopMost = -1
      NoTopMost = -2
    End Enum
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Sub 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)
    
    Private Sub SetWindowPosition(Set_TopMost As TopMostEnum)
      SetWindowPos Me.hWnd, Set_TopMost, 0, 0, 0, 0, All_Flags
    End Sub
    
    Private Sub chkTopMost_Click()
      If chkTopMost.Value = vbChecked Then
        SetWindowPosition TopMost
      Else
        SetWindowPosition NoTopMost
      End If
    End Sub
    
    Private Sub Form_Load()
      Me.Move Screen.Width - 15, (Screen.Height / 2) - (Me.Height / 2)
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Timer1.Enabled = False Then Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
    Dim Mouse As POINTAPI
    
      GetCursorPos Mouse
        If ScaleX(Mouse.X, vbPixels, vbTwips) < Screen.Width And _
           ScaleX(Mouse.X, vbPixels, vbTwips) > Screen.Width - Me.Width And _
           ScaleY(Mouse.Y, vbPixels, vbTwips) < (Screen.Height / 2) + (Me.Height / 2) And _
           ScaleY(Mouse.Y, vbPixels, vbTwips) > Me.Top Then
           
           If chkPopUp.Value = vbChecked Then
             If Not Me.Left = Screen.Width - Me.Width Then Me.Left = Me.Left - 15
           Else
             Me.Left = Screen.Width - Me.Width
            End If
        Else
           If chkPopUp.Value = vbChecked Then
             Me.Left = Me.Left + 15
           Else
             Me.Left = Screen.Width - 1
           End If
        End If
    
        If Me.Left = Screen.Width - 15 Then Timer1.Enabled = False
    End Sub
    Attached Files Attached Files

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Is there a way to dock a form to the right side of the users screen regardless of

    Quote Originally Posted by Max187Boucher View Post
    Ok Justin I made you a small example also using getcursorpos to be more precise in its activation (popping in and out). I have included a slow popping in and out function and also the setwindowpos.

    Code:
    Option Explicit
    
    Const All_Flags = &H10 Or &H40 Or &H2 Or &H1
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Enum TopMostEnum
      TopMost = -1
      NoTopMost = -2
    End Enum
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Sub 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)
    
    Private Sub SetWindowPosition(Set_TopMost As TopMostEnum)
      SetWindowPos Me.hWnd, Set_TopMost, 0, 0, 0, 0, All_Flags
    End Sub
    
    Private Sub chkTopMost_Click()
      If chkTopMost.Value = vbChecked Then
        SetWindowPosition TopMost
      Else
        SetWindowPosition NoTopMost
      End If
    End Sub
    
    Private Sub Form_Load()
      Me.Move Screen.Width - 15, (Screen.Height / 2) - (Me.Height / 2)
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Timer1.Enabled = False Then Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
    Dim Mouse As POINTAPI
    
      GetCursorPos Mouse
        If ScaleX(Mouse.X, vbPixels, vbTwips) < Screen.Width And _
           ScaleX(Mouse.X, vbPixels, vbTwips) > Screen.Width - Me.Width And _
           ScaleY(Mouse.Y, vbPixels, vbTwips) < (Screen.Height / 2) + (Me.Height / 2) And _
           ScaleY(Mouse.Y, vbPixels, vbTwips) > Me.Top Then
           
           If chkPopUp.Value = vbChecked Then
             If Not Me.Left = Screen.Width - Me.Width Then Me.Left = Me.Left - 15
           Else
             Me.Left = Screen.Width - Me.Width
            End If
        Else
           If chkPopUp.Value = vbChecked Then
             Me.Left = Me.Left + 15
           Else
             Me.Left = Screen.Width - 1
           End If
        End If
    
        If Me.Left = Screen.Width - 15 Then Timer1.Enabled = False
    End Sub
    Oh that is some srly cool stuff right there!

    Thank you guys for your help!

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: [RESOLVED] Is there a way to dock a form to the right side of the users screen re

    Hi again Max, I just had one question. Is there a way to get the retracting to stop when the form width is 210?

    I just think that if there is a little "stub" of the toolbar, the new users will be able to find the toolbar easier.

    Thank you guys so much.

  10. #10
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [RESOLVED] Is there a way to dock a form to the right side of the users screen re

    Here would be the modification.

    Code:
    Option Explicit
    
    Const All_Flags = &H10 Or &H40 Or &H2 Or &H1
    
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    
    Enum TopMostEnum
      TopMost = -1
      NoTopMost = -2
    End Enum
    
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Sub 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)
    Private HiddenBorder As Integer
    
    Private Sub SetWindowPosition(Set_TopMost As TopMostEnum)
      SetWindowPos Me.hWnd, Set_TopMost, 0, 0, 0, 0, All_Flags
    End Sub
    
    Private Sub chkTopMost_Click()
      If chkTopMost.Value = vbChecked Then
        SetWindowPosition TopMost
      Else
        SetWindowPosition NoTopMost
      End If
    End Sub
    
    Private Sub Form_Load()
      HiddenBorder = 210
      Me.Move Screen.Width - HiddenBorder, (Screen.Height / 2) - (Me.Height / 2)
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Timer1.Enabled = False Then Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
    Dim Mouse As POINTAPI
    
      GetCursorPos Mouse
        If ScaleX(Mouse.X, vbPixels, vbTwips) < Screen.Width And _
           ScaleX(Mouse.X, vbPixels, vbTwips) > Screen.Width - Me.Width And _
           ScaleY(Mouse.Y, vbPixels, vbTwips) < (Screen.Height / 2) + (Me.Height / 2) And _
           ScaleY(Mouse.Y, vbPixels, vbTwips) > Me.Top Then
           
           If chkPopUp.Value = vbChecked Then
             If Not Me.Left = Screen.Width - Me.Width Then Me.Left = Me.Left - 15
           Else
             Me.Left = Screen.Width - Me.Width
            End If
        Else
           If chkPopUp.Value = vbChecked Then
             Me.Left = Me.Left + 15
           Else
             Me.Left = Screen.Width - HiddenBorder
           End If
        End If
    
        If Me.Left = Screen.Width - HiddenBorder Then Timer1.Enabled = False
    End Sub

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: [RESOLVED] Is there a way to dock a form to the right side of the users screen re

    Oh this is great! One last question I had for you was I really like the slow retract, so I would always like to have that. Is there a way to have the timer do that without needing the checkbox?

    Thanks a lot!!!

  12. #12
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [RESOLVED] Is there a way to dock a form to the right side of the users screen re

    Yes i originally programmed it without checkbox, it was a last minute addition, i will remove it tonight if you didnt figure it out
    Or if i got time i'll modify from my phone.

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: [RESOLVED] Is there a way to dock a form to the right side of the users screen re

    Quote Originally Posted by Max187Boucher View Post
    Yes i originally programmed it without checkbox, it was a last minute addition, i will remove it tonight if you didnt figure it out
    Or if i got time i'll modify from my phone.
    Oh that's ok Max. I played around and got it.

    I was however, wondering if there was a way when the program first runs, to keep the toolbar from retracting when it first loads? Then after the user moves the mouse away from the toolbar, then it can retract like it does now?

    Thanks!

  14. #14
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [RESOLVED] Is there a way to dock a form to the right side of the users screen re

    Well that is easy its in the form_load event

    Code:
    Private Sub Form_Load()
      HiddenBorder = 210
      Me.Move Screen.Width - Me.Width, (Screen.Height / 2) - (Me.Height / 2)
    End Sub
    Last edited by Max187Boucher; Mar 27th, 2014 at 11:58 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