get focused control
Published: 27. January 2009 | Updated: 9. October 2011License: Microsoft Public License (MS-PL)
Categories: Windows » Win32, Winforms
Tags: C# Controls Win32 Winforms
Import namespaces
using System.Runtime.InteropServices; using System.Windows.Forms;
Win API
[DllImport("user32.dll")] static extern IntPtr GetFocus();
Use
Control focused = null; IntPtr handle = GetFocus(); if (handle != IntPtr.Zero) { focused = Control.FromHandle(handle); }
| Send us feedback about this snippet » |





