Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

Wrapping "SysIPAddress32" focus issues

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Normski - 14 Dec 2004 08:26 GMT
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
"Jeffrey Tan[MSFT]" - 15 Dec 2004 07:28 GMT
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
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

"Jeffrey Tan[MSFT]" - 17 Dec 2004 01:11 GMT
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
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.