如何防止表单集中在鼠标单击上? [英] How to prevent a form from receiving focus on mouse click?

查看:85
本文介绍了如何防止表单集中在鼠标单击上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 2010,C#;阻止表单将焦点放在鼠标单击上,而是将焦点发送到表单后面的控件上.

我有两种形式.第二种形式是总是在第一种形式的顶部".它所覆盖的区域始终是富文本框.我的最终目标是当单击form2时,form1变为活动状态,并且富文本框被激活,以便"I"光标闪烁并可以键入.另外,单击的位置应显示为"I".

换句话说: 我可以点击通过"表格吗?

谢谢你.我在整个互联网上进行搜索以找到解决方案,但无济于事,没有找到我的任何需求.尚无任何工作.这是我尝试过的:

在form2.cs

Visual Studio 2010, C#; Preventing a form from receiving focus on mouse click, and instead send focus to the control on the form behind it.

I have two forms. The second form is always "on top" of the first form. And the area that it is covering is always a rich text box. My ultimate goal is that when form2 is clicked, form1 becomes active, and the rich text box is activated so that the ''I'' cursor blinks and I can type. Also, the place where is clicked, should appear the ''I''.

In other words: Can I click ''through'' the form?

Thank you. I have searched all over the internet to find the solution to this and to no avail, did not find anything of my needs. Nothing which has worked yet. This is what I have tried:

In form2.cs

SetStyle(ControlStyles.Selectable, false);
and
this.Enabled = false;



再次感谢您.



Thank you once again.

推荐答案

看看这个:它向您展示了如何做.
http://stackoverflow.com/questions/4964205/non-transparent-click-透过表单上网 [ ^ ]
Have a look at this: it shows you how to do it.
http://stackoverflow.com/questions/4964205/non-transparent-click-through-form-in-net[^]


使用代码

this.Focus();

该代码将使焦点集中在表单上.您可以编写textbox1并将其焦点放在textbox1上.
示例:
https://rapidshare.com/files/1759098260/Exemple.rar [
Use code

this.Focus();

this code will give focus to form.Instead of this you can write textbox1 and it will give focus to textbox1.
Example:
https://rapidshare.com/files/1759098260/Exemple.rar[^]


我解决了...最后.

只需将这段代码放入表单的类中即可.

I solved it... Finally.

Just place this code into the class of your form.

protected override void WndProc(ref Message m)
        {
            if (m.Msg == (int)0x84)
                m.Result = (IntPtr)(-1);
            else
                base.WndProc(ref m);
        }


这将阻止该表单处于活动状态,从而无法在该表单下方"发送所有鼠标命令;形成1.


This will prevent that form from being active, there for sending all mouse commands ''under'' that form; to form 1.


这篇关于如何防止表单集中在鼠标单击上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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