启用/禁用窗体的激活 [英] Enable/Disable activation of a Form

查看:157
本文介绍了启用/禁用窗体的激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从被激活禁用表格。要做到这一点我用这样的:



<预类=郎-CS prettyprint-覆盖> 私人const int的WS_EX_NOACTIVATE = 0x08000000;
保护覆盖的CreateParams的CreateParams
{
得到
{
的CreateParams的CreateParams = base.CreateParams;
createParams.ExStyle = WS_EX_NOACTIVATE;
回报率的CreateParams;
}
}

这是罚款,我的程序,因为主要活动我仍然可以点击按钮和表格不会激活。无论程序是在前台停留在那里。



现在的问题是在我的节目开始时,我需要输入一些文字用键盘和该表格必须是活动的,否则文本将转到前台程序。



我知道,当我想启用。/禁用表格的能力被激活,我只是不知道如何



编辑:当它的不能够被激活了我还是想形式的按钮,可点击。这里的代码,它的工作原理像。真正的问题是在一开始时,我想输入一些文字。


解决方案

我发现了一个在互联网搜索更加之后简单的一条线的解决方案:



启动();



不知道这一点的存在。使用中的问题的代码加上这对的Form_Load 我可以有计划在一开始主动和保持这种方式,直到我换到另一个程序。之后,我的程序将永远不会再次激活。
除非我把一个按钮或东西,调用激活()一次。


I want to disable a Form from being activated. To do that I use this:

private const int WS_EX_NOACTIVATE = 0x08000000;
protected override CreateParams CreateParams
{
   get
      {
          CreateParams createParams = base.CreateParams;
          createParams.ExStyle = WS_EX_NOACTIVATE;
          return createParams;
       }
}

This is fine for the main activity of my program because I can still click on the buttons and the Form won't activate. Whatever program is in the foreground stays there.

The problem is at the beginning of my program I need to input some text with the keyboard and for that the Form must be active or else the text will go to the program in the foreground.

I know where and when I want to enable/disable the Form ability to be activated, I just don't know how.

EDIT: And when it's not able to be active anymore I still want the buttons of the form to be clickable. With the code here it works like that. The real problem is at the beginning when I want to input some text.

解决方案

After searching even more around the Internet I found a simple one line solution:

Activate();

Didn't know this existed. Using the code in the question plus this on Form_Load I can have the program active at the beginning and stays that way until I change to another program. After that my program will never be active again. Unless I put a button or something that calls Activate() again.

这篇关于启用/禁用窗体的激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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