应用程序重点的得失 [英] Application focus getting and losing

查看:58
本文介绍了应用程序重点的得失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想写一个屏幕键盘,但是当它有焦点时我不能写,
例如:打开记事本时,我想输入一些单词,这不是因为我的应用程序获得了焦点!
为此,我的应用程序应该失去焦点,而我想在其中键入单词的应用程序(例如记事本)应该获得焦点.
我不知道该怎么做!

Hi,
I want to write a on screen keyboard , but when it has focus I can not write,
for example : when i open notepad , and I want to type some word , it doesn''t because my app gets focus!
for this my app should lose focus and the application that i want to type words in it(like notepad)should gets focus.
I don''t know how to do this!
thank''s in advance.

推荐答案

您需要的是这样的:

What you need is this:

internal static class User32Constants {
    internal const int WS_EX_TOPMOST = 8;
    internal const int WS_EX_NOACTIVATE = 0x08000000;
    //...
}



在您的虚拟键盘形式中,添加:



In your Virtual keyboard form, add:

protected override CreateParams CreateParams {
    get {
        CreateParams par = base.CreateParams;
        if (DesignMode) return par;
        par.ExStyle |= User32Constants.WS_EX_TOPMOST;
        par.ExStyle |= User32Constants.WS_EX_NOACTIVATE;
        return par;
    } //get CreateParams
} //CreateParams



WS_EX_TOPMOST的使用用作属性TopMost(可以代替使用).
这里有三个微妙的时刻:当专注于用于输入的控件WS_EX_NOACTIVATE时,需要最大的行为以不将表格隐藏在后面-以避免被虚拟键盘抓住焦点(Nishant之前已经解释过).对DesignMode进行检查有助于避免万一您使用它时中断表单设计器.

我敢打赌,您的下一个问题将是关于从虚拟控件发送输入的问题.没有多少人能正确地做到这一点.提示:在我最近的答案之一中找到答案.

—SA



The use of WS_EX_TOPMOST works as the property TopMost (which could be used instead).
There three delicate moments: topmost behavior is needed to not hide the form behind when focusing on a control to be used for input, WS_EX_NOACTIVATE — to avoid grabbing focus by the virtual keyboard (Nishant explained that before). The check of DesignMode is good to avoid disrupting of the Form Designer in case you use it.

I bet your next question would be about sending input from the virtual control; not many do it correctly. A hint: find an answer in one of my recent Answers.

—SA


通常,这是通过创建具有WS_EX_NOACTIVATE样式的窗口来完成的.在C#中,您不直接创建窗口(或窗体),但可以尝试覆盖CreateParams 属性(然后从窗体中删除该样式):

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.createparams.aspx [ ^ ]
Typically this is done by creating the window with the WS_EX_NOACTIVATE style. In C#, you don''t directly create the window (or form), but you can try overriding the CreateParams property (and then remove that style from your form):

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.createparams.aspx[^]


感谢所有回复.

现在我可以用c锐笔来做..

我如何使用vb.net做到这一点
如果可以的话.
Thank you for all reply.

now i can do it with c sharp..

how can i make it using vb.net
if you can help me.


这篇关于应用程序重点的得失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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