Wrapping "SysIPAddress32" focus issues

  • Thread starter Thread starter Normski
  • Start date Start date
N

Normski

I'm wrapping to wrap SysIPAddress32 window control, I tried doing this using
a NativeWindow and a ordinary Control by overriding the CreateParams method.

The window seems to create ok, but there are focus issues, if I add this
control on a form with another control say a TextBox if I give the TextBox
focus and then click back to the hosted SysIPAddress32 window control the
TextBox does recieve a Leave message, any ideas. Without going under the
hood I stump to tell what's going on. BTW: I have tried using Spy++ it seems
"like" the messages should be routed to the correct windows (I could be
wrong).


Norm
 
Hi Normski,

Thanks for your posting!

Yes, I have reproduced out your issue. For this issue, I have done some
research and find a workaround which may meet your need.

We may inherit a child class from the NativeWindow class, then use this
class to listen for the message of TextBox, then we can intercept the
WM_KILLFOCUS message of TextBox, and we may use this message as the new
event for TextBox's Leave event, code snippet lists below:

public Form1()
{
//Add event handler in Form's constructor
InitializeComponent();
MyNativeWindowListener obj=new MyNativeWindowListener(this.textBox1);
}

public class MyNativeWindowListener: NativeWindow
{
private Control tb;

public MyNativeWindowListener(Control tb)
{

tb.HandleCreated += new EventHandler(this.OnHandleCreated);
tb.HandleDestroyed+= new EventHandler(this.OnHandleDestroyed);
this.tb = tb;
}

// Listen for the control's window creation and then hook into it.
internal void OnHandleCreated(object sender, EventArgs e)
{
// Window is now created, assign handle to NativeWindow.
AssignHandle(((Control)sender).Handle);
}
internal void OnHandleDestroyed(object sender, EventArgs e)
{
// Window was destroyed, release hook.
ReleaseHandle();
}

const int WM_KILLFOCUS=0x8;

[System.Security.Permissions.PermissionSet(System.Security.Permissions.Secur
ityAction.Demand, Name="FullTrust")]
protected override void WndProc(ref Message m)
{
// Listen for operating system messages

if(m.Msg==WM_KILLFOCUS)
{
Console.WriteLine("abc");
}
base.WndProc(ref m);
}
}

It works well on my side, hope it helps you.
========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Norm,

Does my workaround of using NativeWindow to intercept the WM_KILLFOCUS for
textbox make sense to you? If you still have any concern on this issue,
please feel free to tell me. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top