1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using ControlExs;
  11.  
  12. namespace TransForm
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19.  
  20. //// 定义在窗体上,光标显示为手形
  21. this.Cursor = System.Windows.Forms.Cursors.Hand;
  22. //// 定义窗体的标题名称
  23. this.Text = "透明的WinForm窗体!";
  24. //// 定义窗体的开始显示位置是屏幕的中间
  25. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  26. //// 窗体的边界是Fixed3D类型
  27. //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  28. ////以桌面的前景色作为窗体的前景色
  29. this.ForeColor = System.Drawing.SystemColors.Desktop;
  30. //// 定义字体类型,大小
  31. this.Font = new System.Drawing.Font("宋体", );
  32. //// 定义背景色为蓝色
  33. this.BackColor = System.Drawing.Color.White;
  34. // 设置窗体的大小
  35. //this.ClientSize = new System.Drawing.Size(440, 170);
  36. // Opacity属性设立窗体的透明程度,只对于视窗2000有效
  37. this.Opacity = 0.60;
  38. }
  39.  
  40. private void Form1_Load(object sender, EventArgs e)
  41. {
  42. this.SetWindowTransparent();
  43. }
  44.  
  45. private void SetWindowTransparent(byte bAlpha)
  46. {
  47. try
  48. {
  49. WinAPI.SetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE, WinAPI.GetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE) | (uint)WinAPI.ExWindowStyle.WS_EX_LAYERED);
  50. WinAPI.SetLayeredWindowAttributes(this.Handle, , bAlpha, WinAPI.LWA_COLORKEY | WinAPI.LWA_ALPHA);
  51. }
  52. catch
  53. {
  54.  
  55. }
  56. }
  57.  
  58. protected override CreateParams CreateParams
  59. {
  60. get
  61. {
  62. CreateParams cp = base.CreateParams;
  63. cp.Parent = WinAPI.GetDesktopWindow();
  64. cp.ExStyle = 0x00000080 | 0x00000008; //WS_EX_TOOLWINDOW | WS_EX_TOPMOST
  65. return cp;
  66. }
  67. }
  68. }
  69. }
  1. public class WinAPI
  2. {
  3. [DllImport("user32.dll")]
  4. public extern static IntPtr GetDesktopWindow();
  5.  
  6. [DllImport("user32.dll")]
  7. public extern static bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
  8.  
  9. public static uint LWA_COLORKEY = 0x00000001;
  10. public static uint LWA_ALPHA = 0x00000002;
  11.  
  12. [DllImport("user32.dll")]
  13. public extern static uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
  14.  
  15. [DllImport("user32.dll")]
  16. public extern static uint GetWindowLong(IntPtr hwnd, int nIndex);
  17.  
  18. public enum WindowStyle : int { GWL_EXSTYLE = - }
  19. public enum ExWindowStyle : uint { WS_EX_LAYERED = 0x00080000 }
  20. }

C# 制作透明窗体的更多相关文章

  1. WPF透明窗体制作

    原文:WPF透明窗体制作 窗体的样式: <Grid Width="{Binding Width, ElementName=w}" Height="{Binding ...

  2. C#在透明窗体WinForm上面画图(电子尺小工具的实现)

    前几天要做一个微信调一调的外挂,里面用到了尺子测量距离,然后就自己下载了一个电子尺,最近要升级我的跳一跳外挂,然后就准备自己做一个电子尺,嵌入到我的外挂里面,在嵌入到我的外挂之前,我自己做了一个完整版 ...

  3. 【flash】关于flash的制作透明gif的一个小技巧

    关于flash的制作透明gif的一个小技巧 或者说是一个需要注意的地方 1.导出影片|gif,得到的肯定是不透明的.2.想要透明背景,必须通过发布.3.flash中想要发布gif动画的话,不能有文字, ...

  4. gdi+ 高速绘制透明窗体

    gdi+ 高速绘制透明窗体: 方法一: 1.用Iamge对象载入png资源, 2.调用drawimage函数讲图片绘制出了 3.UpdateLayeredWindow对窗体进行布局 方法二: 1.用B ...

  5. qt 获取windows 的消息(通过MFC的DLL的透明窗体转发消息)good

    qt 给win32 发送消息很简单,但是要获取windows 消息却十分复杂,最后想了一个不是很完美 但是也是以现在本人能力所能实现的唯一途径了,基本原理是 利用vc编写一个mfc 的dll ,这个d ...

  6. C/S模式开发中如何利用WebBrowser控件制作导航窗体

    原文:C/S模式开发中如何利用WebBrowser控件制作导航窗体 转自: CSDN 相信不少同学们都做过MIS系统的开发,今天这里不讨论B/S模式开发的问题.来谈谈winform开发.用过市面上常见 ...

  7. DSAPI实现简单的透明窗体

    代码 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim B As New Bitmap( ...

  8. 【转载】Layered Window(分层窗体,透明窗体)

    本文转载自花间醉卧<Layered Window(分层窗体,透明窗体)> //为窗体添加WS_EX_LAYERED属性,该属性使窗体支持透明 ModifyStyleEx(0, WS_EX_ ...

  9. WPF透明窗体不支持缩放解决方案

    方案一 WPF中的无边框透明窗体,由于没有边并且透明,窗体无法进行缩放操作,今天来讲解如何解决这个问题. 先说一下思路,我们先手为该窗体添加4个边,4个角用于缩放操作,然后再为他们写事件,完成拖放操作 ...

随机推荐

  1. openfire 最大连接数调优

    https://community.igniterealtime.org/thread/48064#224126 https://community.igniterealtime.org/thread ...

  2. Spark RDD概念学习系列之RDD是什么?(四)

       RDD是什么? 通俗地理解,RDD可以被抽象地理解为一个大的数组(Array),但是这个数组是分布在集群上的.详细见  Spark的数据存储 Spark的核心数据模型是RDD,但RDD是个抽象类 ...

  3. Javascript函数柯里化(curry)

    函数柯里化currying,是函数式编程非常重要的一个标志.它的实现需要满足以下条件,首先就是函数可以作为参数进行传递,然后就是函数可以作为返回值return出去.我们依靠这个特性编写很多优雅酷炫的代 ...

  4. <系统函数实现>memcmp

    这是我实现的memcmp函数: #include <stdio.h> #include <string.h> /* *int memcmp (const void *s1,co ...

  5. excel分组求和

    =SUMPRODUCT((C2:C99=F2)*(B2:B99)) 说明: C2:C99=F2 找到C2到C99之间的等于F2的值 如果有多个判断条件,采用*来管理 B2:B99 求和

  6. ThinkPad X220i 安装 Mac OSX

    联想笔记本是安装黑苹果相对比较容易的~~ ThinkPad X220i配置   型号:ThinkPad X220i CPU: i3 内存:4G 显卡:HD3000 其他: X220i的通用硬件 确认以 ...

  7. POJ3468 A Simple Problem with Integers(线段树延时标记)

    题目地址http://poj.org/problem?id=3468 题目大意很简单,有两个操作,一个 Q a, b 查询区间[a, b]的和 C a, b, c让区间[a, b] 的每一个数+c 第 ...

  8. MySQL重置密码(OSX)

    1.停止MySQL的服务 sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop   2.cd /usr/local/mysql/bin ./mysqld_ ...

  9. ActiveMQ简介与安装

    开源消息总线 支持JMS1.1和J2EE 1.4规范的 JMS Provider实现(持久化,XA消息,事务) 对Spring的支持,ActiveMQ可以很容易内嵌到使用Spring的系统里面去 支持 ...

  10. winForm开发

    http://www.cnblogs.com/wuhuacong/p/3199829.html http://www.cnblogs.com/peterzb/archive/2009/06/30/15 ...