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个角用于缩放操作,然后再为他们写事件,完成拖放操作 ...
随机推荐
- ERROR (ClientException) nova image-list
nova image-listERROR (ClientException): The server has either erred or is incapable of performi9e-6c ...
- <一道题>求1 + 2! + 3! + .... + N!
一道小题,╮(╯▽╰)╭ #include <stdio.h> /*jie cheng * * 1 + 2! + 3! + ... + N! * * */ int factorial(in ...
- Oracle中INT、FLOAT、NUMBER区别
Oracle里的int等于number(长度,0) float也类似,number要定义小数部分的位数,而float不用定义后边小数有几位 因为NUMBER要确定长度,后边确定小数位. 所以,如果不 ...
- OracleCommand.CommandText 无效
OracleCommand insertADataCmd = conn.CreateCommand(); insertBDataCmd.CommandText = SQL OracleParamete ...
- Median of Two Sorted Arrays-----LeetCode
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted ...
- linq to sql转载
LINQ简介 LINQ:语言集成查询(Language INtegrated Query)是一组用于c#和Visual Basic语言的扩展.它允许编写C#或者Visual Basic代码以查询数据库 ...
- 在Windows2012下安装SQL Server 2005无法启动服务的解决办法
下面是我亲自经历过的总结. 因为尝鲜安装了Windows2012,的确很不错,唯一的遗憾就是不支持Sql Server 2005的安装.找了很多办法,基本上都有缺陷.现在终于找到一种完全正常没有缺陷的 ...
- C++的辅助工具介绍 [转]
C++的辅助工具介绍 1 文档类 (1) Doxygen 参考站点:http://www.doxygen.org Doxygen是一种适合C风格语言(如C++.C.IDL.Java甚至包括C#和 ...
- Linux 网络编程 高级套接字
一.套接字选项: 有以下3中方式可以对套接字选项进行设置: getsockopt 和 setsockopt 函数 fcntl函数 ioctl函数 getsockopt和setsockopt函数用于获得 ...
- vs2010代码注释自动生成api文档
最近做了一些接口,提供其他人调用,要写个api文档,可是我想代码注释已经写了说明,能不能直接把代码注释生成api?于是找到以下方法 环境:vs2010 先下载安装Sandcastle 和Sandcas ...