dimanche 31 août 2014

Need To Close A Panel When Clicked Outside (Lost Focus)


Vote count:

0




I have an issue that I cannot seem to overcome.


In my application, I have a custom class that loads a form into a panel upon startup. Then when I click a button on my main form I show the panel as visible revealing the form to the user.


My problem is that I want to be able to hide the panel when a user clicks outside of it (back onto the main form).


so far I have tried Form_Deactivate, Form_Leave, Form_LostFocus, Panel_Leave and Panel_LostFocus events but nothing will seem to trigger an event consistently to hide the panel. The only thing that works is if the user clicks inside the form (on a listview control) once the form is visible and then clicks outside of the form.


Is there anyway I can ensure this event gets called everytime whether the user clicks the form or not?


So far my code looks something like:



Public Class cls_UserObjects

Private frm As frmUsers
Public pnl As Panel

Public Sub ShowUserPanel()
Try
frm = New frmUsers
frm.TopLevel = False
pnl.Controls.Add(frm)
frm.Show()
frm.Focus()
....
End Class


Then in my main form I call the code below to build the form into the panel:



class_Users.pnl = pnlUsers
class_Users.ShowUserPanel()


And pnlUsers.Visible = True to show it to the user


I just can't seem to close it. I understand that Panels don't support the LostFocus properly, however, I can't find away around this. Maybe it has something to do with how I am opening my form/panel but I was advised to use classes to open forms so I can have more control over the controls within my forms from outside calls.


Any help appreciated. Thanks



asked 5 mins ago

Riples

206






Need To Close A Panel When Clicked Outside (Lost Focus)

Aucun commentaire:

Enregistrer un commentaire