The required function is to obtain the input focus of the textbox when the mouse slides over the textbox of the WPF form.
Steps:
1. Set the topmost attribute of WPF to true.
2. Reference Win32 API functions:
View code [Dllimport ( " User32.dll " )]
Private Static Extern Bool Setforegroundwindow (intptr hwnd );
[Dllimport ("User32.dll")]
Private Static ExternIntptr setfocus (intptr hwnd );
2. Add the textbox mouseenter event
View code Private Void Tbword_mouseenter ( Object Sender, mouseeventargs E)
{
Hwndsource Source = (Hwndsource) presentationsource. fromvisual ( This );
Intptr handle = Source. Handle;
Bool B1 = Bringwindowtotop (handle );
System. Threading. thread. Sleep ( 300 );
bool B = setforegroundwindow (handle);
system. threading. thread. sleep ( 100 );
tbword. focus ();
tbword. selectall ();
}
Program Demo: http://www.cnblogs.com/JimmyXiao/archive/2011/03/17/1987561.html