Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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

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


Thank you once again.
Posted
Updated 7-Jun-12 20:44pm
v3

 
Share this answer
 
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[^]
 
Share this answer
 
Comments
vlad781 8-Jun-12 3:01am    
This is not exactly what I was looking for:

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

I have found my own solution, just now.
I solved it... Finally.

Just place this code into the class of your form.

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

This will prevent that form from being active, there for sending all mouse commands 'under' that form; to form 1.
 
Share this answer
 
Comments
Sandeep Mewara 8-Jun-12 4:02am    
Good you posted what resolved your issue. This might help someone facing similar issue in future.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900