Click here to Skip to main content
Rate this: bad
good
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);
and
this.Enabled = false;
 
Thank you once again.
Posted 7-Jun-12 21:36pm
Edited 7-Jun-12 21:44pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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

Solution 1

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[^]
  Permalink  
Comments
vlad781 at 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
good
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);
            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.
  Permalink  
Comments
Sandeep Mewara at 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
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 Andreas Gieriet 90
4 Jochen Arndt 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 8 Jun 2012
Copyright © CodeProject, 1999-2014
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