C#简单实现窗口全透明
来源:互联网 发布:怎么样开通淘宝 编辑:程序博客网 时间:2024/05/17 03:33
C#简单实现窗口全透明
实现窗口全透明,不管用什么编程语言,其实原理都是一样的,为了进一步展现各语言实现整个窗口全透明,现将C#的源码送上,供大家参考。
我用的编写环境为:Windows Vista 、 Visual Studio 2008
效果图如下:
程
程序实现源码:
//Form1.cs
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 WindowsVistaFormsApplication
{
public partial class Form1 : Form
{
int en;
GraphicsPath fontpath;
GraphicsPath glowpath;
PathGradientBrush pathbrush;
Graphics gph;
//API 结构声明
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();
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 on Windows 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();
}
}
}
}
源码下载: http://download.csdn.net/source/714815
发布:薛雪 E_mail:SnowEmail3074@163.com
备注:实现方法虽然很简单,转载时敬请注明出处,谢谢!
- C#简单实现窗口全透明
- VB简单实现窗口全透明
- MFC对话框简单实现窗口全透明的方法
- MFC对话框简单实现窗口全透明的方法
- Gtk透明窗口全攻略
- Gtk透明窗口全攻略
- Gtk透明窗口全攻略
- Activity全透明实现
- gtk+实现透明窗口
- 如何实现透明窗口
- MFC实现透明窗口
- 实现窗口透明
- 透明窗口的实现
- java实现窗口透明
- wxPython 窗口实现透明
- VC实现透明窗口
- C# WPF设置窗口透明
- 实现导航栏全透明
- Javascript中的||运算符
- Javascript脚本:Location对象
- 如何替换系统记事本(notepad.exe)
- 【经验分享】C#调试数据查询的一个小技巧。
- freebsd安装以及配置pkg_add
- C#简单实现窗口全透明
- ASP与JSP的比较
- 领悟JavaScript中的面向对象
- 地理信息系统比较牛的网站(原创)---之可以丰富你的GIS知识
- 随感
- 指针问题
- javascript中replace()用法详解
- 什么是APT?
- MFC应用程序中指针的使用