EDN Admin
Well-known member
Hi I was trying to get a transparent form like a glass which could enable clickthrough and every mouse event to pass to the windows or items behind the glass.
So this is the code I wrote with WindowForms:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; namespace ClickThroughMe
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class ClickThroughForm : Form
{
<span style="color:Blue; private <span style="color:Blue; int currentWindowStyle;
<span style="color:Blue; public ClickThroughForm()
{
InitializeComponent();
}
<span style="color:Blue; private <span style="color:Blue; void ClickThroughForm_Load(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Green; // Grab the Extended Style information for this window and store it.
currentWindowStyle = WindowLibrary.User32Wrappers.GetWindowLong(<span style="color:Blue; this.Handle, User32Wrappers.GWL.ExStyle);
<span style="color:Green; // Set our window to "transparent", or invisible to the mouse.
SetFormToTransparent();
<span style="color:Green; // Make our window the top-most form.
<span style="color:Blue; this.TopMost = <span style="color:Blue; true;
}
<span style="color:Blue; private <span style="color:Blue; void SetFormToTransparent()
{
<span style="color:Green; // This creates a new extended style for our window, making it transparent to the mouse.
User32Wrappers.SetWindowLong(<span style="color:Blue; this.Handle, User32Wrappers.GWL.ExStyle,
(User32Wrappers.WS_EX) currentWindowStyle |
User32Wrappers.WS_EX.Layered |
User32Wrappers.WS_EX.Transparent);
}
}
}
[/code]
<br/>
The problem with this code is that whole window get transparent though opacity and controls such buttons or sliders do not retain clickability.<br/>
<br/>
So I need help to make it better.
1) Retain controls Full Opacity (Not needed but important)
2) Retain controls Clickability and Operativity (MUST)
I accept any solution, even changing the project to WPF if this can help getting the result.<br/>
<br/>
Thanks for you time.
View the full article
So this is the code I wrote with WindowForms:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; namespace ClickThroughMe
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class ClickThroughForm : Form
{
<span style="color:Blue; private <span style="color:Blue; int currentWindowStyle;
<span style="color:Blue; public ClickThroughForm()
{
InitializeComponent();
}
<span style="color:Blue; private <span style="color:Blue; void ClickThroughForm_Load(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Green; // Grab the Extended Style information for this window and store it.
currentWindowStyle = WindowLibrary.User32Wrappers.GetWindowLong(<span style="color:Blue; this.Handle, User32Wrappers.GWL.ExStyle);
<span style="color:Green; // Set our window to "transparent", or invisible to the mouse.
SetFormToTransparent();
<span style="color:Green; // Make our window the top-most form.
<span style="color:Blue; this.TopMost = <span style="color:Blue; true;
}
<span style="color:Blue; private <span style="color:Blue; void SetFormToTransparent()
{
<span style="color:Green; // This creates a new extended style for our window, making it transparent to the mouse.
User32Wrappers.SetWindowLong(<span style="color:Blue; this.Handle, User32Wrappers.GWL.ExStyle,
(User32Wrappers.WS_EX) currentWindowStyle |
User32Wrappers.WS_EX.Layered |
User32Wrappers.WS_EX.Transparent);
}
}
}
[/code]
<br/>
The problem with this code is that whole window get transparent though opacity and controls such buttons or sliders do not retain clickability.<br/>
<br/>
So I need help to make it better.
1) Retain controls Full Opacity (Not needed but important)
2) Retain controls Clickability and Operativity (MUST)
I accept any solution, even changing the project to WPF if this can help getting the result.<br/>
<br/>
Thanks for you time.
View the full article