Click here to Skip to main content
13,055,047 members (53,129 online)
Rate this:
Please Sign up or sign in to 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

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

Thank you once again.
Posted 7-Jun-12 20:36pm
Updated 7-Jun-12 20:44pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use code


this code will give focus to form.Instead of this you can write textbox1 and it will give focus to textbox1.
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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);
                base.WndProc(ref m);

This will prevent that form from being active, there for sending all mouse commands 'under' that form; to form 1.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 8 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100