Mouse click and MDI child forms

A

Ahmed Kamal

Hi all,

Why is it that clicking on controls on child forms does not activate the
form? E.g. I have a parent form with 2 children, both have frames
containing controls. Only if I click on the form title itself then will
it be activated.

This is a problem when the tops of child forms are obscured, meaning
that I have to manually drag forms around to get to the child. This is
very bad design in my opinion, VB6 did not have this problem, so I don't
understand why VB.NET appears to have it.

I have found few posts on the internet related to this problem, so I
assume I must be doing something wrong. Does anyone know the answer? It
would be a big help to me really, I can't be expected to put a
Me.Activate() function call for each control's _Click() event.

Thank you for reading!

Kamal
 
M

Morten Wennevik

Hi Ahmed,

I can't verify your problem, it always activates for me, the title being
hidden or not (Using C# though, but that shouldn't make a difference here).

Can you post a small but complete code sample demonstrating your problem?


Happy coding!
Morten Wennevik [C# MVP]
 
A

Ahmed Kamal

Hi Morten,

You know what, you're absolutely right! I just did an empty app with a
couple of windows, the problem did not occur. However the problem does
show up in the app that my staff did, which is quite complicated at this
stage so it's difficult for me to trim it down and post the code for u.

Basically the program structure is this:

frmMain = parent form
frmSearch = simple form with a datagrid, showing a list of customers.
frmCustomer = form with detailed fields describing a customer record

When the user Selects 'Customer' from frmMain's menu, frmSearch pops up.
The datagrid is populated.
When the user clicks a row, an instance of frmCustomer is created and
all the fields are filled in. So if the user clicks multiple records,
multiple frmCustomer windows are created.

All these forms are children of frmMain. When I click on them, or their
controls, their window does not receive focus UNLESS I click on the
window titlebar. However if I am currently at window A and then click on
a textbox in window B, I can type info there even though window B is not
the currently selected window.

Weird huh? I do not understand what would cause this behaviour, because
frmCustomer does not have any form_click or form_activate events.

I'd appreciate any suggestions you might have.

Kamal
 
M

Morten Wennevik

Not quite sure what the problem might be, but I would check any code using
Focus, Activate, Validation or similar.

Is this problem only related to frmSearch having focus, and then trying to
click on a frmCustomer control? Or do you have the same problem if one
frmCustomer form has focus, and then clicking on a control in another
frmCustomer?

Happy coding!
Morten Wennevik [C# MVP]
 
A

Ahmed Kamal

frmSearch has a Form_Click() method to refresh the datagrid. frmCustomer
has no form activate/click/focus methods at all.

I use frmSearch for Customers,Suppliers,Lorries and other things. Even
among the multiple frmSearch instances, I get the same problem! Its
almost as though any form that is a child of my parent form suffers from
this.

Lets say I have multiple instances of frmSearch and frmCustomer on the
form. Regardless of which form is active, when I click on another form
it is not activated unless I click on the title bar.

I'm so confused. Maybe when the project is done I can pass you the code
via email together with a login name for our sql server.

Hmm maybe there is something wrong with the parent?

Regards,

Kamal
 
M

Morten Wennevik

I'm sorry, but I have run out of ideas. Are you intercepting user input
somewhere? so that mouse click events gets posted to the currently focused
window instead of whatever window you click on? For all I know it could
be something very simple, but I am unable to spot it :(

Hopefully someone else will pick up on this thread.

Happy coding!
Morten Wennevik [C# MVP]
 
A

Ahmed Kamal

Hi,

Ok, I tried a different approach to the problem:

First I created a new MDI form together with two new child forms
(Form1,Form2). Everything works fine. However when testing with the
other existing forms like frmCustomer/frmSearch, then the
child-switching problem occurs. Even Form1 and Form2 which previously
had no problem getting activated wherever I clicked on them, suddenly
had the problem!

So I took frmCustomer and removed all the data adapter, sqlconnection
stuff and tested it. It failed.

Then I removed the controls a bit at a time, testing at each stage.
Still failed.

Now frmCustomer is COMPLETELY empty, and still creates the problem!

Ok, so I created a completely new MDI application, added Form1 and
Form2. It tested ok. I copied and pasted frmCustomer in, and guess what?
Everything worked OK. Then I tried adding the database access module and
frmSearch, made some changes so it could work...then the symptoms showed
up again, even for frmCustomer. Form1 and Form2 however remain
unaffected. They share the same properties as frmCustomer though. I
removed the recent addins, leaving behind Form1,Form2 and frmCustomer,
which previously had no problem working together.

Now frmCustomer still doesn't work! Its almost as though adding the
module and frmSearch 'infected' frmCustomer and gave it the problem. Yet
Form1 and Form2 are still fine. There are no references to frmCustomer
in the database access module. One method in frmSearch does create an
instance of frmCustomer though. That is the only link between the new
files and frmCustomer.

Deleting frmCustomer and copy/paste a new copy from the original doesn't
help either. This is strange because copy/paste was the way I got it to
work in the first place.

These errors don't make sense. I'm getting very frustrated. I have
uploaded the files from the new application I created to:

http://www.applecatstudios.com/problem.zip

Please may someone out there look thru the files...you can open the
solution and run it, you will find that the moment an instance of
frmCustomer is created, then child-switching no longer works properly.
But you can create as many instances of Form1 and Form2 as you want
before that and everything works fine.

Thank you thank you thank you.

Kamal
 
A

Ahmed Kamal

Hi Alok,

Oh dear, your advice came too late. But at least now I know what caused
the problem- my staff typed in the Me.Select() and forgot about it,
since the constructor code doesn't show up unless u select it in the
IDE. Gosh. You know what I did to solve it?? I made a new form, copied
all the controls and code into it, made necessary renaming adjustments
and voila it worked! Hahaha...if only I read your post a couple of hours
ago ;)

Now to track down the other two people I found on google who had the
same problem but didn't have the benefit of your advice :)

THANK YOU ALOK! Thank you to Morten too!

Regards,

Kamal
Hi Ahmed,
I could finally track down your problem.
In the constructor of the frmCustomer, after Initializecomponent() call,
remove the line Me.Select()
The focus problem was due to that.

Hope this Helps :)

Hi,

Ok, I tried a different approach to the problem:

First I created a new MDI form together with two new child forms
(Form1,Form2). Everything works fine. However when testing with the
other existing forms like frmCustomer/frmSearch, then the
child-switching problem occurs. Even Form1 and Form2 which previously
had no problem getting activated wherever I clicked on them, suddenly
had the problem!

So I took frmCustomer and removed all the data adapter, sqlconnection
stuff and tested it. It failed.

Then I removed the controls a bit at a time, testing at each stage.
Still failed.

Now frmCustomer is COMPLETELY empty, and still creates the problem!

Ok, so I created a completely new MDI application, added Form1 and
Form2. It tested ok. I copied and pasted frmCustomer in, and guess what?
Everything worked OK. Then I tried adding the database access module and
frmSearch, made some changes so it could work...then the symptoms showed
up again, even for frmCustomer. Form1 and Form2 however remain
unaffected. They share the same properties as frmCustomer though. I
removed the recent addins, leaving behind Form1,Form2 and frmCustomer,
which previously had no problem working together.

Now frmCustomer still doesn't work! Its almost as though adding the
module and frmSearch 'infected' frmCustomer and gave it the problem. Yet
Form1 and Form2 are still fine. There are no references to frmCustomer
in the database access module. One method in frmSearch does create an
instance of frmCustomer though. That is the only link between the new
files and frmCustomer.

Deleting frmCustomer and copy/paste a new copy from the original doesn't
help either. This is strange because copy/paste was the way I got it to
work in the first place.

These errors don't make sense. I'm getting very frustrated. I have
uploaded the files from the new application I created to:

http://www.applecatstudios.com/problem.zip

Please may someone out there look thru the files...you can open the
solution and run it, you will find that the moment an instance of
frmCustomer is created, then child-switching no longer works properly.
But you can create as many instances of Form1 and Form2 as you want
before that and everything works fine.

Thank you thank you thank you.

Kamal

Morten said:
I'm sorry, but I have run out of ideas. Are you intercepting user input
somewhere? so that mouse click events gets posted to the currently
focused window instead of whatever window you click on? For all I know
it could be something very simple, but I am unable to spot it :(

Hopefully someone else will pick up on this thread.

Happy coding!
Morten Wennevik [C# MVP]
 
A

Alok

Hi Ahmed,
I could finally track down your problem.
In the constructor of the frmCustomer, after Initializecomponent() call,
remove the line Me.Select()
The focus problem was due to that.

Hope this Helps :)

Ahmed Kamal said:
Hi,

Ok, I tried a different approach to the problem:

First I created a new MDI form together with two new child forms
(Form1,Form2). Everything works fine. However when testing with the
other existing forms like frmCustomer/frmSearch, then the
child-switching problem occurs. Even Form1 and Form2 which previously
had no problem getting activated wherever I clicked on them, suddenly
had the problem!

So I took frmCustomer and removed all the data adapter, sqlconnection
stuff and tested it. It failed.

Then I removed the controls a bit at a time, testing at each stage.
Still failed.

Now frmCustomer is COMPLETELY empty, and still creates the problem!

Ok, so I created a completely new MDI application, added Form1 and
Form2. It tested ok. I copied and pasted frmCustomer in, and guess what?
Everything worked OK. Then I tried adding the database access module and
frmSearch, made some changes so it could work...then the symptoms showed
up again, even for frmCustomer. Form1 and Form2 however remain
unaffected. They share the same properties as frmCustomer though. I
removed the recent addins, leaving behind Form1,Form2 and frmCustomer,
which previously had no problem working together.

Now frmCustomer still doesn't work! Its almost as though adding the
module and frmSearch 'infected' frmCustomer and gave it the problem. Yet
Form1 and Form2 are still fine. There are no references to frmCustomer
in the database access module. One method in frmSearch does create an
instance of frmCustomer though. That is the only link between the new
files and frmCustomer.

Deleting frmCustomer and copy/paste a new copy from the original doesn't
help either. This is strange because copy/paste was the way I got it to
work in the first place.

These errors don't make sense. I'm getting very frustrated. I have
uploaded the files from the new application I created to:

http://www.applecatstudios.com/problem.zip

Please may someone out there look thru the files...you can open the
solution and run it, you will find that the moment an instance of
frmCustomer is created, then child-switching no longer works properly.
But you can create as many instances of Form1 and Form2 as you want
before that and everything works fine.

Thank you thank you thank you.

Kamal

Morten said:
I'm sorry, but I have run out of ideas. Are you intercepting user input
somewhere? so that mouse click events gets posted to the currently
focused window instead of whatever window you click on? For all I know
it could be something very simple, but I am unable to spot it :(

Hopefully someone else will pick up on this thread.

Happy coding!
Morten Wennevik [C# MVP]
 
A

Alok

that is the worst part of VS .Net IDE :)
Windows Generated Code !!!!

Ahmed Kamal said:
Hi Alok,

Oh dear, your advice came too late. But at least now I know what caused
the problem- my staff typed in the Me.Select() and forgot about it,
since the constructor code doesn't show up unless u select it in the
IDE. Gosh. You know what I did to solve it?? I made a new form, copied
all the controls and code into it, made necessary renaming adjustments
and voila it worked! Hahaha...if only I read your post a couple of hours
ago ;)

Now to track down the other two people I found on google who had the
same problem but didn't have the benefit of your advice :)

THANK YOU ALOK! Thank you to Morten too!

Regards,

Kamal
Hi Ahmed,
I could finally track down your problem.
In the constructor of the frmCustomer, after Initializecomponent() call,
remove the line Me.Select()
The focus problem was due to that.

Hope this Helps :)

Hi,

Ok, I tried a different approach to the problem:

First I created a new MDI form together with two new child forms
(Form1,Form2). Everything works fine. However when testing with the
other existing forms like frmCustomer/frmSearch, then the
child-switching problem occurs. Even Form1 and Form2 which previously
had no problem getting activated wherever I clicked on them, suddenly
had the problem!

So I took frmCustomer and removed all the data adapter, sqlconnection
stuff and tested it. It failed.

Then I removed the controls a bit at a time, testing at each stage.
Still failed.

Now frmCustomer is COMPLETELY empty, and still creates the problem!

Ok, so I created a completely new MDI application, added Form1 and
Form2. It tested ok. I copied and pasted frmCustomer in, and guess what?
Everything worked OK. Then I tried adding the database access module and
frmSearch, made some changes so it could work...then the symptoms showed
up again, even for frmCustomer. Form1 and Form2 however remain
unaffected. They share the same properties as frmCustomer though. I
removed the recent addins, leaving behind Form1,Form2 and frmCustomer,
which previously had no problem working together.

Now frmCustomer still doesn't work! Its almost as though adding the
module and frmSearch 'infected' frmCustomer and gave it the problem. Yet
Form1 and Form2 are still fine. There are no references to frmCustomer
in the database access module. One method in frmSearch does create an
instance of frmCustomer though. That is the only link between the new
files and frmCustomer.

Deleting frmCustomer and copy/paste a new copy from the original doesn't
help either. This is strange because copy/paste was the way I got it to
work in the first place.

These errors don't make sense. I'm getting very frustrated. I have
uploaded the files from the new application I created to:

http://www.applecatstudios.com/problem.zip

Please may someone out there look thru the files...you can open the
solution and run it, you will find that the moment an instance of
frmCustomer is created, then child-switching no longer works properly.
But you can create as many instances of Form1 and Form2 as you want
before that and everything works fine.

Thank you thank you thank you.

Kamal

Morten Wennevik wrote:

I'm sorry, but I have run out of ideas. Are you intercepting user input
somewhere? so that mouse click events gets posted to the currently
focused window instead of whatever window you click on? For all I know
it could be something very simple, but I am unable to spot it :(

Hopefully someone else will pick up on this thread.

Happy coding!
Morten Wennevik [C# MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top