Transparent form that intercepts mouse events

P

pigeonrandle

Hi,
I am trying (with little (no) success) to create a transparent form
that can capture mouse events. Put another way, i would like to show
the other windows that are behind my form (like setting the form
transparency key to the form backcolor), but i dont want the mouse
clicks to pass through my form and on to the windows behind.

Can i perhaps do this with a message filter? by deregistering the
filter that must already be there to pass the mouse clicks on? or maybe
by overriding WndProc and handling the mouse events there?

If anyone has any ideas as to how i might accomplish this, then i will
herald them as an intellectual leviathan!

James Randle.
 
S

Steve

Hi,
If you create a form with the same dimensions and location of your
current form, then all messages will go to that form anyway. Here's
some code that creates a transparent form and displays it over the
current form when the button is clicked. When this new form is shown,
all windows messages go to it and so nothing is accessible on the form
underneath. The form is a standard form with a button and a label.
When the button is clicked, the new (transparent) form is show on top
of it.

Hope this helps.

Cheers,

Steve Dunn.
http://stevedunns.blogspot.com

public partial class Form1 : Form
{
private Form _form;

public Form1()
{
InitializeComponent();

_form = new Form();
_form.FormBorderStyle = FormBorderStyle.None;
_form.Opacity = .5;
_form.ShowInTaskbar = false;
_form.KeyDown += delegate(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
_form.Hide();
label1.Text = @"We're not covered";
}
};
}


private void button1_Click(object sender, EventArgs e)
{
_form.Show(this);
_form.Bounds = this.Bounds;
_form.Location = this.Location;
label1.Text = @"We're covered. Press escape";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top