如何创建在 Windows 10 中看到的透明效果?像这样的事情:
我不知道如何在 C# 中解决这个问题。从逻辑上讲,每次表单进入焦点时我都会拍摄桌面快照。然后对其进行模糊处理并将其放置在 0, 0(屏幕到客户端坐标)处。这似乎不太有效。有什么帮助吗?再次。不是经验丰富的 C# 程序员,所以详细的解释将不胜感激
编辑:我看到一些答案将我引向阿尔法混合页面。这不是我要找的。我想知道如何创建您在图像中看到的模糊效果,其余的我可以按照自己的节奏弄清楚
尽管所有评论和答案都说这对于 WinForms 是不可能的,但它绝对也适用于 WinForms(如SetWindowCompositionAttribute
可以在 Win32 窗口句柄上调用):
internal enum AccentState
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_INVALID_STATE = 4
}
internal enum WindowCompositionAttribute
{
WCA_ACCENT_POLICY = 19
}
[StructLayout(LayoutKind.Sequential)]
internal struct AccentPolicy
{
public AccentState AccentState;
public int AccentFlags;
public int GradientColor;
public int AnimationId;
}
[StructLayout(LayoutKind.Sequential)]
internal struct WindowCompositionAttributeData
{
public WindowCompositionAttribute Attribute;
public IntPtr Data;
public int SizeOfData;
}
internal static class User32
{
[DllImport("user32.dll")]
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
}
然后在您的 Form 构造函数中:
public Form1()
{
InitializeComponent();
BackColor = Color.Black; // looks really bad with the default back color
var accent = new AccentPolicy { AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND };
var accentStructSize = Marshal.SizeOf(accent);
var accentPtr = Marshal.AllocHGlobal(accentStructSize);
Marshal.StructureToPtr(accent, accentPtr, false);
var data = new WindowCompositionAttributeData
{
Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
SizeOfData = accentStructSize,
Data = accentPtr
}
User32.SetWindowCompositionAttribute(Handle, ref data);
Marshal.FreeHGlobal(accentPtr);
}
Result:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)