最快的方式获得的WinForms C#集中控制? [英] Fastest way to get focused control in WinForms c#?

查看:134
本文介绍了最快的方式获得的WinForms C#集中控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序来测试某些键并给予空间,右,左,与其它一些特殊的处理我的主窗体窗口使用ProcessCmdKey。如果用户在TextBox一组嵌套的用户控件内输入的主要形式ProcessCmdKey甚至被称为。我不想处理空格键时,他们都集中在一个TextBox控件,因为他们从来没有能够键入一个空格。我如何可以测试当前焦点窗口的应用范围的基础上的类型?

I'm using ProcessCmdKey in my main form window for the application to test for certain keys and give Space, Right, Left, and a few others special processing. ProcessCmdKey in the main form is called even if the user is typing in a TextBox inside a nested set of user controls. I don't want to process the Space key when they are focused on a TextBox control, since they'd never be able to type a space. How can I test for the type of the currently focused window on an application wide basis?

推荐答案

您可以用此得到的窗口句柄:

You can get the window handle with this:

  [DllImport("user32.dll")]
  private static extern IntPtr GetFocus();



然后你就可以得到与该句柄相关联的.NET控件(如果有)与<一个HREF =http://msdn.microsoft.com/en-us/library/system.windows.forms.control.fromhandle.aspx> Control.FromHandle 。

这篇关于最快的方式获得的WinForms C#集中控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆