How to

get focused control

Published: 27. January 2009 | Updated: 9. October 2011
License: Microsoft Public License (MS-PL)
Categories: Windows » Win32, Winforms
Tags: C# Controls Win32 Winforms
Was this snippet helpful for you? YESYES / NONO
Get Analyzant!

Check your entire website from code to content in minutes with Analyzant, the free analysis suite.

Free download at

Import namespaces

using System.Runtime.InteropServices;
using System.Windows.Forms;


static extern IntPtr GetFocus();


Control focused = null;
IntPtr handle = GetFocus();
if (handle != IntPtr.Zero)
    focused = Control.FromHandle(handle);
Send us feedback about this snippet »

Related Snippets: