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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Activate / DeActivate 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
Very confused here. If I'm working in one form and click onto a 2nd form, the first form's deactivate does not fire if I click on the grid in the 2nd form, but it does fire if I click on the 2nd form's header. Also the 2nd form's activate does not fire either. This seems strange, how can I determine when the user has clicked off of the first form onto any control on the 2nd form?

Auguy
Northwest Ohio
 
It's working for me. I created two test form's and coded the following events for each:

Code:
    Private Sub frmTest1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Me.Text = ("Test2 Activated")
    End Sub

    Private Sub frmTest1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
        Me.Text = ("Test2 Deactivate")
    End Sub

Seems to work just fine.
 
Oh, and this was using two controls on each form-- a text box and datagridview, tested with clicking on the blank area of the forms, in the controls, and on the headers.
 
Thanks RiverGuy. I guess I have some more investigation to do to see why mine isn't working like that.

Auguy
Northwest Ohio
 
Now I'm really confused. I have duplicated RiverGuy's example and my example does not work as he described. As I click between the two forms, unless I click on the header of the form(s) the activate and deactivate events do not fire on either form. The only difference is my VB.net (2003) does not allow me to specify the Handles as Me.Activated or Me.Deactivate, they are Mybase.Activated and Mybase.Deactivate. Does anyone have any ideas as to why my example doesn't work? Is there a Windows Forms or project setting that controls this behavior?

Auguy
Northwest Ohio
 
I was using VB 2005. I just tested with 2003, with a brand new project, and I get the same results as my 2005 project.
 
Thanks RiverGuy. I was able to duplicate your results when I started a new project from scratch. Now I have to figure out why my original project doesn't work correctly. The big difference in my live project is I have a form (MainForm) with a menu on it that allows me to show other forms. In my Sub Main (my startup object) I use MainForm.ShowDialog(). Could this be causing the problem? Is there another way to use this form as my main interface for the project?

Auguy
Northwest Ohio
 
It seems to work for me with start with Sub Main and a ShowDialog for Form1. A put a button that when clicked makes and shows copies of Form2. I tried toggling between Form1, and two copies of Form2, so three forms in all, and I get the Activated/Deactivated events as expected.
 
RierGuy, thanks again. I've traced it back to myForm1.MdiParent = Me in the MainApp form when I open a form as follows:
Code:
Dim myForm1 as New Form1
myForm1.MdiParent = Me
mfForm1.show()
Dim myForm2 as New Form2
myForm2.MdiParent = Me
mfForm2.show()
If I remove the MdiParent from both they work just fine. I will have to investigate what removing these will do to the rest of the project.


Auguy
Northwest Ohio
 
Very weird. I just tried converting my project to an MDI project, and the Activate/Deactivate is still working properly between the MDI children.
 
Ok, I have it working in the small test project with the MdiParent code as descibed above, but still won't work in the main project. I guess it's time to start deleting things until it works.

Auguy
Northwest Ohio
 
I think I have finally traced this down to a form I was defining and setting the MdiParent of in the MainApp form:
Code:
Public ProMainForm As New ProMain
ProMainForm.MdiParent = Me
as soon as I remove the MdiParent line everything appears to work normally. Still some testing to do though to be sure this is really the problem.


Auguy
Northwest Ohio
 
Forgot. Thanks again RiverGuy for your patience. Hopefully this is resolved. I don't know why that causes the problem, but at least I think I can work around it.

Auguy
Northwest Ohio
 
Back again. Since the original post, I have everything working fine except for two forms that are instantiated from the same base form. The form activate and deactivate don't work consistently on these two. I'm guessing my problem has something to do with these two being based on the same form. More.... investigation to do!


Auguy
Northwest Ohio
 
Do you have any code running in any GotFocus or LostFocus events of any controls on these forms, or in the forms themselves? I have tested this also, and in my test I instantiated 3 forms all from the same base form, and it worked fine.





I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Yes, I do have a few Got and Lost focus events for a few controls on the form. None on the form, just Activated and Deactivate. I think I will have to start removing controls and event processing until it works correctly so I can find out what is causing this problem.

Auguy
Northwest Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top