|
刚刚看到有人在问,记得以前我用过,贴出来吧省得大家走弯路:
首先编写一个Utils类(当然写在你的Form里面也可以哈~),里面加上如下代码 [DllImport("coredll.dll")]
private static extern IntPtr GetFocus();
[DllImport("coredll.dll")]
private static extern int SendMessage(IntPtr hWnd, uint Message, uint wParam, uint lParam);
public static void txt_GotFocus(object sender, EventArgs e)
{
IntPtr ptr1 = Utils.GetFocus();
Utils.SendMessage(ptr1, 0xde, 0, 2);
(sender as TextBox).SelectAll();
}
然后在你的Form里面给你的TextBox加上这个: this.YourTextBox.GotFocus += new EventHandler(Utils.txt_GotFocus);
以上代码SP2003SE测试通过
|