欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

C# WinForm实现Win7 Aero透明效果代码

时间:2021-08-25 08:01:19|栏目:.NET代码|点击:

在Vista系统之后,微软为窗体程序提供了Aero磨砂的效果,如下图。那么用C#如何来实现这种磨砂效果呢?

背景为我的桌面
那先上代码吧:

[StructLayout(LayoutKind.Sequential)] 
public struct MARGINS 
{ 
  public int Left; 
  public int Right; 
  public int Top; 
  public int Bottom; 
} 
 
[DllImport("dwmapi.dll", PreserveSig = false)] 
static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins); 
 
[DllImport("dwmapi.dll", PreserveSig = false)] 
static extern bool DwmIsCompositionEnabled(); 
 
public Form1() 
{ 
  InitializeComponent(); 
} 
 
protected override void OnLoad(EventArgs e) 
{ 
  if (DwmIsCompositionEnabled()) 
  { 
    MARGINS margins = new MARGINS(); 
    margins.Right = margins.Left = margins.Top = margins.Bottom = this.Width + this.Height; 
    DwmExtendFrameIntoClientArea(this.Handle, ref margins); 
  } 
  base.OnLoad(e); 
} 
 
protected override void OnPaintBackground(PaintEventArgs e) 
{ 
  base.OnPaintBackground(e); 
  if (DwmIsCompositionEnabled()) 
  { 
    e.Graphics.Clear(Color.Black); 
  } 
} 

这中效果的实现主要是调用了系统的dwmapi.dll。

dwmapi.dll是Microsoft Desktop Window Manager API(桌面窗口管理器DWM 的公用界面)的动态链接库,正常文件,主要用作桌面效果的api。DWM 是一种新界面,在除 Windows Vista Home Basic 之外的所有 Windows Vista 版本中均提供 DWM 界面。

所以这种效果只能在Vista之后的系统中使用。

上一篇:C#中FormsAuthentication用法实例

栏    目:.NET代码

下一篇:asp.net生成静态后冗余代码,去掉viewstate生成的代码

本文标题:C# WinForm实现Win7 Aero透明效果代码

本文地址:http://www.codeinn.net/misctech/169666.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有