得到焦点控件

来源:互联网 发布:手机号码定位追踪软件 编辑:程序博客网 时间:2024/04/28 00:46

public class MyForm : Form 

{ 

[DllImport("user32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.Winapi)] 

internal static extern IntPtr GetFocus(); 

//得到焦点控件

private Control GetFocusedControl() 

{

Control focusedControl = null; 

// To get hold of the focused control: 

IntPtr focusedHandle = GetFocus(); 

if(focusedHandle != IntPtr.Zero) 

// Note that if the focused Control is not a .Net control, then this will return null.

focusedControl = Control.FromHandle(focusedHandle); 

return focusedControl; 

} 

}

原创粉丝点击