Get focus control

xiaoxiao2021-03-06  41

Public Class MyForm: Form

{

[DLLIMPORT ("User32.dll", Charset = Charset.auto, CallingConvention = CALLINGCONVENTION.WINAPI)]

INTERNAL STATIC EXTERN INTPTR getFocus ();

// Get focus controls

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, THIS WILL RETURN NULL.

FocusedControl = Control.FromHandle (FocusedHandle);

Return FocusedControl;

}

}

转载请注明原文地址:https://www.9cbs.com/read-57108.html

New Post(0)