469,140 Members | 1,205 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,140 developers. It's quick & easy.

Transparent form that intercepts mouse events

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.

Dec 17 '06 #1
2 5103

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";
}
}

On Dec 17, 3:39 pm, "pigeonrandle" <pigeonran...@hotmail.comwrote:
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.
Dec 17 '06 #2
seems like this would be best accomplished by a hook.

http://support.microsoft.com/kb/318804/
http://msdn.microsoft.com/newsgroups...0379e54c9b&p=1

just some links for you...

hope this helps
--
-iwdu15
Dec 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Trevor Fairchild | last post: by
2 posts views Thread by Henrik | last post: by
9 posts views Thread by don | last post: by
3 posts views Thread by Steve Koon | last post: by
reply views Thread by anishkphilip | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.