C# 制作透明窗体
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 ControlExs; namespace TransForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); //// 定义在窗体上,光标显示为手形
this.Cursor = System.Windows.Forms.Cursors.Hand;
//// 定义窗体的标题名称
this.Text = "透明的WinForm窗体!";
//// 定义窗体的开始显示位置是屏幕的中间
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
//// 窗体的边界是Fixed3D类型
//this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
////以桌面的前景色作为窗体的前景色
this.ForeColor = System.Drawing.SystemColors.Desktop;
//// 定义字体类型,大小
this.Font = new System.Drawing.Font("宋体", );
//// 定义背景色为蓝色
this.BackColor = System.Drawing.Color.White;
// 设置窗体的大小
//this.ClientSize = new System.Drawing.Size(440, 170);
// Opacity属性设立窗体的透明程度,只对于视窗2000有效
this.Opacity = 0.60;
} private void Form1_Load(object sender, EventArgs e)
{
this.SetWindowTransparent();
} private void SetWindowTransparent(byte bAlpha)
{
try
{
WinAPI.SetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE, WinAPI.GetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE) | (uint)WinAPI.ExWindowStyle.WS_EX_LAYERED);
WinAPI.SetLayeredWindowAttributes(this.Handle, , bAlpha, WinAPI.LWA_COLORKEY | WinAPI.LWA_ALPHA);
}
catch
{ }
} protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Parent = WinAPI.GetDesktopWindow();
cp.ExStyle = 0x00000080 | 0x00000008; //WS_EX_TOOLWINDOW | WS_EX_TOPMOST
return cp;
}
}
}
}
public class WinAPI
{
[DllImport("user32.dll")]
public extern static IntPtr GetDesktopWindow(); [DllImport("user32.dll")]
public extern static bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags); public static uint LWA_COLORKEY = 0x00000001;
public static uint LWA_ALPHA = 0x00000002; [DllImport("user32.dll")]
public extern static uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong); [DllImport("user32.dll")]
public extern static uint GetWindowLong(IntPtr hwnd, int nIndex); public enum WindowStyle : int { GWL_EXSTYLE = - }
public enum ExWindowStyle : uint { WS_EX_LAYERED = 0x00080000 }
}
C# 制作透明窗体的更多相关文章
- WPF透明窗体制作
原文:WPF透明窗体制作 窗体的样式: <Grid Width="{Binding Width, ElementName=w}" Height="{Binding ...
- C#在透明窗体WinForm上面画图(电子尺小工具的实现)
前几天要做一个微信调一调的外挂,里面用到了尺子测量距离,然后就自己下载了一个电子尺,最近要升级我的跳一跳外挂,然后就准备自己做一个电子尺,嵌入到我的外挂里面,在嵌入到我的外挂之前,我自己做了一个完整版 ...
- 【flash】关于flash的制作透明gif的一个小技巧
关于flash的制作透明gif的一个小技巧 或者说是一个需要注意的地方 1.导出影片|gif,得到的肯定是不透明的.2.想要透明背景,必须通过发布.3.flash中想要发布gif动画的话,不能有文字, ...
- gdi+ 高速绘制透明窗体
gdi+ 高速绘制透明窗体: 方法一: 1.用Iamge对象载入png资源, 2.调用drawimage函数讲图片绘制出了 3.UpdateLayeredWindow对窗体进行布局 方法二: 1.用B ...
- qt 获取windows 的消息(通过MFC的DLL的透明窗体转发消息)good
qt 给win32 发送消息很简单,但是要获取windows 消息却十分复杂,最后想了一个不是很完美 但是也是以现在本人能力所能实现的唯一途径了,基本原理是 利用vc编写一个mfc 的dll ,这个d ...
- C/S模式开发中如何利用WebBrowser控件制作导航窗体
原文:C/S模式开发中如何利用WebBrowser控件制作导航窗体 转自: CSDN 相信不少同学们都做过MIS系统的开发,今天这里不讨论B/S模式开发的问题.来谈谈winform开发.用过市面上常见 ...
- DSAPI实现简单的透明窗体
代码 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim B As New Bitmap( ...
- 【转载】Layered Window(分层窗体,透明窗体)
本文转载自花间醉卧<Layered Window(分层窗体,透明窗体)> //为窗体添加WS_EX_LAYERED属性,该属性使窗体支持透明 ModifyStyleEx(0, WS_EX_ ...
- WPF透明窗体不支持缩放解决方案
方案一 WPF中的无边框透明窗体,由于没有边并且透明,窗体无法进行缩放操作,今天来讲解如何解决这个问题. 先说一下思路,我们先手为该窗体添加4个边,4个角用于缩放操作,然后再为他们写事件,完成拖放操作 ...
随机推荐
- Ubuntu14.04上安装pip的方法
在Ubuntu14.04上,建议通过下面的方法安装,这是一种通用的方法,也适用于Windows,当然在Windows下 手动下载下来就行了 wget https://bootstrap.pypa.io ...
- 【MySQL】源码编译安装和配置MySql 5.5.32(单实例)
[需求描述] 在CentOS环境中,通过编译源码的方式,安装并且配置“单实例”的MySQL5.5.32数据库. MySQL的安装目录为:/application/mysql-5.5.32 MySQL数 ...
- Maven+Spring Batch+Apache Commons VF学习
Apache Commons VFS资料:例子:http://www.zihou.me/html/2011/04/12/3377.html详细例子:http://p7engqingyang.iteye ...
- Linux查看系统信息命令总结
系统 # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinf ...
- 原生的AJAX写法,可以直接复制过来套用
方法一: function createXMLHTTPRequest() { //1.创建XMLHttpRequest对象 //这是XMLHttpReuquest对象无部使用中最复杂的一步 //需要针 ...
- CSS元素水平居中和垂直居中的方法大全
水平居方法: 1.最熟悉的是给元素定义一个宽度,然后使用margin: body{ width:960px; margin:0 auto;}这个是当我们的定义元素的宽度时显现的,如果我们不能定义宽度时 ...
- 在drupal7中动态的为某个内容类型添加字段
$myField_name = "my_new_field_name"; if(!field_info_field($myField_name)) // check if the ...
- SQL2005/8数据库提示单个用户无法操作的解决方法
原因分析: 是操作数据库的用户被锁定了,思路是通过查找目标用户,将其解锁即可,可是这样太麻烦了. 解决办法执行如下sql: USE master; GO DECLARE @SQL VARCHAR( ...
- VM VirtualBox 上安装 CentOs6.4(详细)
在网上下载:CentOS-6.4-i386-bin-DVD1.iso镜像. 这是我在VBox上安装CentOs6.4的过程: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12 ...
- android 自定义控件(初篇)
android 自定义控件 在写UI当中很多时候会用到自定义的控件,其实自定义控件就像是定义一个类进行调用就OK了.有些相关的感念可以查看API 下面就用个简单的例子来说明自定义控件: public ...