If you really don't need the mouse location except for knowing if the mouse is within the MDI child, put your code inside the MouseEnter event handler of the MDI child. if you created MDIchild at runtime by something like:
MDIChild MDIchild = new MDIChild();
you can assign the event handler dynamically immediatly after the initializing of the instance by adding the following line after the line above:
MDIchild.MouseEnter +=
new EventHandler(MDIchild_MouseEnter);
Of course you will need to add a method MDIchild_MouseEnter(object sender, EventArgs e) to your class containing the code you want to execute (MDIchild.createObject();)
All mouse events of the form do not work when the form is an MDI parent (MouseClick, MouseEnter, MouseLeave, MouseDoubleClick ... etc.) The reason is in the previous post so i guess that makes the post by Chi the primary Answer
! However, what i'm saying is that you might not need the MouseMove and the CheckHit() method at all!
A better code, if you create many child forms and you want all of them to call createObject when the mouse enters them, will be to create a general MouseEnter event handler for all your child forms, something like the following (assuming all your child forms are of Type MDIChild):
void MDIChild_MouseEnter(object sender, EventArgs e){
MDIChild temp = (MDIChild)(sender);
temp.createObject();
}
Then, whenever you create a new MDI child, you just assign this general event handler to its MouseEnter event:
MDIChild newInstance = new MDIChild();
newInstance.MouseEnter += new EventHandler(MDIChild_MouseEnter);
This will do for your code i guess!
Hope this helped.