Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form close when clicking outside

Status
Not open for further replies.

160473

IS-IT--Management
Apr 16, 2003
55
FI
A have created a form as a custom menu but I don't know how to close it if I click outside it (same behaviour as a contextmenu). The form i opened when I right-click on a datagrid.
 
perhaps in the onlostfocus event ro leave event.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Neither of those work, chrissie, however MouseLeave sort of works.

Private Sub Form3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MouseLeave
Me.Close()
End Sub

However the form closes when the mouse leaves the form - ie it doesn't need a click anywhere

[vampire][bat]
 
nope...

If i put me.close() in 'Private Sub Form9_LostFocus(By...Handles MyBase.LostFocus' then the form closes directly after it opens... Maby because it contains buttons, labels, comboboxes...
 
Of course if you are feeling brave, there is a way you could almost certainly get the exact effect that you require.

To do this you would need to handle the WndProc event (from the overrides section) and check all the mouse messages to see if they represent a click away from your form.

This is something I personally wouldn't do unless there was no other solution - probably someone like Chiph, if he reads this could give you a helping hand.


Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top