嗨,我试图获得像玻璃一样的透明形式,它可以使点击和每个鼠标事件传递到玻璃后面的窗户或物品。
所以这是我用 WindowForms 编写的代码:
namespace ClickThroughMe
{
public partial class ClickThroughForm : Form
{
private int currentWindowStyle;
public ClickThroughForm()
{
InitializeComponent();
}
private void ClickThroughForm_Load(object sender, EventArgs e)
{
// Grab the Extended Style information for this window and store it.
currentWindowStyle = WindowLibrary.User32Wrappers.GetWindowLong(this.Handle, User32Wrappers.GWL.ExStyle);
// Set our window to "transparent", or invisible to the mouse.
SetFormToTransparent();
// Make our window the top-most form.
this.TopMost = true;
}
private void SetFormToTransparent()
{
// This creates a new extended style for our window, making it transparent to the mouse.
User32Wrappers.SetWindowLong(this.Handle, User32Wrappers.GWL.ExStyle,
(User32Wrappers.WS_EX) currentWindowStyle |
User32Wrappers.WS_EX.Layered |
User32Wrappers.WS_EX.Transparent);
}
}
}
此代码的问题是整个窗口通过不透明度变得透明,但控制此类按钮或滑块不保留可点击性。
所以我需要帮助让它变得更好。
1)保留控件完全不透明度(不需要但很重要)
2)保留控制可点击性和可操作性(必须)
我接受任何解决方案,甚至将项目更改为 WPF,如果这有助于获得结果。
谢谢你的时间。