如何用C#做出aero效果的界面,用windows Form界面,最好是毛玻璃效果或者水滴效果
如题,是否需要什么插件呢?如何引用,或者用什么语句能达到该目的(是全透明,但字体和ico图标必须清晰,不是调节VS里的透明度)...
如题,是否需要什么插件呢?如何引用,或者用什么语句能达到该目的(是全透明,但字体和ico图标必须清晰,不是调节VS里的透明度)
展开
2个回答
展开全部
我以前做过一个,这是主要代码,需要添加引用dwmapi.dll
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
namespace AeroForm
{
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 = 0;
MARGINS mg = new MARGINS(); //定义透明扩展区域的大小,这里全部-1,即全部透明
mg.m_Buttom = -1;
mg.m_Left = -1;
mg.m_Right = -1;
mg.m_Top = -1;
//判断是否Vista及以上的系统
if (System.Environment.OSVersion.Version.Major >= 6)
{
DwmIsCompositionEnabled(ref en); //检测Aero是否为打开
if (en > 0)
{
DwmExtendFrameIntoClientArea(this.Handle, ref mg); //透明
}
else
{
MessageBox.Show("Desktop Composition is Disabled!"); //未开启透明桌面
}
}
else
{
MessageBox.Show("Please run this at least on Windows Vista."); //至少在vista运行
}
this.Paint += new PaintEventHandler(Form1_Paint);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
if (en > 0)
{
Graphics g = e.Graphics;
SolidBrush bsh = new SolidBrush(Color.Black);
g.FillRectangle(bsh, this.ClientRectangle);
bsh.Dispose();
}
Graphics h = this.CreateGraphics();
GraphicsPath blackfont = new GraphicsPath();
SolidBrush brsh = new SolidBrush(Color.Black);
blackfont.AddString("你想写的字", new FontFamily("微软雅黑"), (int)FontStyle.Regular, 26, new Point(30, 30), StringFormat.GenericDefault);
h.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
h.FillPath(brsh, blackfont);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
namespace AeroForm
{
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 = 0;
MARGINS mg = new MARGINS(); //定义透明扩展区域的大小,这里全部-1,即全部透明
mg.m_Buttom = -1;
mg.m_Left = -1;
mg.m_Right = -1;
mg.m_Top = -1;
//判断是否Vista及以上的系统
if (System.Environment.OSVersion.Version.Major >= 6)
{
DwmIsCompositionEnabled(ref en); //检测Aero是否为打开
if (en > 0)
{
DwmExtendFrameIntoClientArea(this.Handle, ref mg); //透明
}
else
{
MessageBox.Show("Desktop Composition is Disabled!"); //未开启透明桌面
}
}
else
{
MessageBox.Show("Please run this at least on Windows Vista."); //至少在vista运行
}
this.Paint += new PaintEventHandler(Form1_Paint);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
if (en > 0)
{
Graphics g = e.Graphics;
SolidBrush bsh = new SolidBrush(Color.Black);
g.FillRectangle(bsh, this.ClientRectangle);
bsh.Dispose();
}
Graphics h = this.CreateGraphics();
GraphicsPath blackfont = new GraphicsPath();
SolidBrush brsh = new SolidBrush(Color.Black);
blackfont.AddString("你想写的字", new FontFamily("微软雅黑"), (int)FontStyle.Regular, 26, new Point(30, 30), StringFormat.GenericDefault);
h.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
h.FillPath(brsh, blackfont);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询