[开发笔记]-实现winform半透明毛玻璃效果

亲测win7下可用,win8下由于系统不支持Aero效果,所以效果不是半透明的。

代码:

博客园插入不了代码了。。。。。

public partial class Form1 : Form
{
int en; public struct MARGINS
{
public int m_Left;
public int m_Right;
public int m_Top;
public int m_Buttom;
}; [DllImport("dwmapi.dll")]
private static extern void DwmIsCompositionEnabled(ref int enabledptr);
[DllImport("dwmapi.dll")]
private static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margin); public Form1()
{
InitializeComponent();
en = ;
MARGINS mg = new MARGINS(); //定义透明扩展区域的大小,这里全部-1,即全部透明
mg.m_Buttom = -;
mg.m_Left = -;
mg.m_Right = -;
mg.m_Top = -; //判断是否Vista及以上的系统
if (System.Environment.OSVersion.Version.Major >= )
{
DwmIsCompositionEnabled(ref en); //检测Aero是否为打开
if (en > )
{
DwmExtendFrameIntoClientArea(this.Handle, ref mg); //透明
} } this.Paint += new PaintEventHandler(Form1_Paint); } private void Form1_Paint(object sender, PaintEventArgs e)
{
if (en > )
{
Graphics g = e.Graphics;
SolidBrush bsh = new SolidBrush(Color.Black);
g.FillRectangle(bsh, this.ClientRectangle);
bsh.Dispose();
}
} private void Form1_Load(object sender, EventArgs e)
{ }
}

win7下的效果为半透明毛玻璃效果,win8下的效果:

[开发笔记]-实现winform半透明毛玻璃效果

转载请注明出处。

上一篇:vue项目node升级后,node-saas报错解决办法


下一篇:操作MySQL出错提示“BLOB/TEXT column request_data in key specification without a key length”解决办法