child control focus msg

  • Thread starter Thread starter Greg Lose
  • Start date Start date
G

Greg Lose

Hey All - I'm looking for a way for a parent control to
receive notification when a child control receives the
focus. Ideally the parent control would receive a
notification even if the child control is many levels
down - ie a control of a control.

I attempted to add a msg filter that cheked for the
WM_SETFOCUSmsg but strangely enough that msg never
appeared in my filter.
 
Hi Creg,
You can't catch WM_SETFOCUS in you message fitler because it is sent rather
than posted. You can catch only posted messages.

I can't think of any workaround but hook Enter or GotFocus events for all
controls of yours.

B\rgds
100
 
Hi Greg,

I agree with our community member, the WM_SETFOCUS message is sent not
posted in message queue. So the IMessageFilter does not work for this case.

If all the child controls are added into the parent control in design time.
maybe you can write your own serializer and serialize a statement like

this.panel1.ControlAdded += new
System.Windows.Forms.ControlEventHandler(this.Form1_ControlAdded);
before the statement collection.

In the event handler , add the event handler for the GotFocus event.
private void Form1_ControlAdded(object sender, ControlEventArgs e)
{
e.Control.GotFocus +=new EventHandler(Control_GotFocus);
}

You may read Shawn's Techincal Article for how to write a customized Code
Serializer for your parent control:
http://msdn.microsoft.com/library/en-us/dndotnet/html/custcodegen.asp?frame=
true

If you would like to try hooking ,here is two Articles on how to use hook
in .NET Framework
<Windows Hooks in the .NET Framework>
http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/default.aspx
<HOW TO: Set a Windows Hook in Visual C# .NET>
http://support.microsoft.com/?kbid=318804

If you meet any problem on this issue, please be free to reply this thread.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 
Back
Top