ManofTheWest
ManofTheWest

Reputation: 23

Vscrollbar doesn't disappear after titlebar click

There is a vscrollbar in my project which i want to make it disappear if the mouse clicks anything outside it. i already tried (Leave) and (Lost Focus) events and they were successful:

Private Sub VScrollBar1_Leave(sender As Object, e As EventArgs) Handles VScrollBar1.Leave

    VScrollBar1.Visible = False

End Sub
Private Sub VScrollBar1_LostFocus(sender As Object, e As EventArgs) Handles VScrollBar1.LostFocus

    VScrollBar1.Visible = False

End Sub

the problem is when clicking the (Titlebar), nothing happens and scrollbar is still visible, any suggestions?

Upvotes: 1

Views: 85

Answers (1)

GME
GME

Reputation: 156

Titlebar has no click event but you can (create) one for it

your code works fine, you just need to add this code:

Private Const WM_NCLBUTTONDOWN As Long = &HA1
Protected Overrides Sub DefWndProc(ByRef m As System.Windows.Forms.Message)
    If CLng(m.Msg) = WM_NCLBUTTONDOWN Then
        Focus()
    End If
    MyBase.DefWndProc(m)
End Sub

this will get focus on your form, which will make your code work perfect...

Upvotes: 1

Related Questions