代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
制作鼠标穿透窗体
作者:
wifi
/ 发布于
2012/12/12
/
595
Frm_Main.cs View Code 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; namespace MouseThroughForm { public partial class Frm_Main : Form { public Frm_Main() { InitializeComponent(); } private const uint WS_EX_LAYERED = 0x80000; private const int WS_EX_TRANSPARENT = 0x20; private const int GWL_EXSTYLE = (-20); private string Var_genre = "";//记录当前操作的类型 #region 在窗口结构中为指定的窗口设置信息 /// <summary> /// 在窗口结构中为指定的窗口设置信息 /// </summary> /// <param name="hwnd">欲为其取得信息的窗口的句柄</param> /// <param name="nIndex">欲取回的信息</param> /// <param name="dwNewLong">由nIndex指定的窗口信息的新值</param> /// <returns></returns> [DllImport("user32", EntryPoint = "SetWindowLong")] private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong); #endregion #region 从指定窗口的结构中取得信息 /// <summary> /// 从指定窗口的结构中取得信息 /// </summary> /// <param name="hwnd">欲为其获取信息的窗口的句柄</param> /// <param name="nIndex">欲取回的信息</param> /// <returns></returns> [DllImport("user32", EntryPoint = "GetWindowLong")] private static extern uint GetWindowLong(IntPtr hwnd, int nIndex); #endregion #region 使窗口有鼠标穿透功能 /// <summary> /// 使窗口有鼠标穿透功能 /// </summary> private void CanPenetrate() { uint intExTemp = GetWindowLong(this.Handle, GWL_EXSTYLE); uint oldGWLEx = SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED); } #endregion private void Frm_Main_Load(object sender, EventArgs e) { this.ShowInTaskbar = false;//窗体不出现在Windows任务栏中 CanPenetrate(); this.TopMost = true;//使窗体始终在其它窗体之上 } #region 设置颜色和透明度的状态 /// <summary> /// 设置颜色和透明度的状态 /// </summary> private void SetEstate(Form Frm, object sender) { Var_genre = ((ToolStripMenuItem)sender).Name; string Tem_Str = Var_genre; if (Var_genre.IndexOf('_') >= 0) { Var_genre = Tem_Str.Substring(0, Tem_Str.IndexOf('_')); } switch (Var_genre) { case "ToolColor": { Color Tem_Color=Color.Gainsboro; switch (Convert.ToInt32(((ToolStripMenuItem)sender).Tag.ToString())) { case 1: Tem_Color = Color.Gainsboro; break; case 2: Tem_Color = Color.DarkOrchid; break; case 3: Tem_Color = Color.RoyalBlue; break; case 4: Tem_Color = Color.Gold; break; case 5: Tem_Color = Color.LightGreen; break; } Frm.BackColor = Tem_Color; break; } case "ToolClarity": { double Tem_Double = 0.0; switch (Convert.ToInt32(((ToolStripMenuItem)sender).Tag.ToString())) { case 1: Tem_Double = 0.1; break; case 2: Tem_Double = 0.2; break; case 3: Tem_Double = 0.3; break; case 4: Tem_Double = 0.4; break; case 5: Tem_Double = 0.5; break; case 6: Tem_Double = 0.6; break; case 7: Tem_Double = 0.7; break; case 8: Tem_Double = 0.8; break; case 9: Tem_Double = 0.9; break; } Frm.Opacity = Tem_Double; break; } case "ToolAcquiescence": { Frm.BackColor = Color.Gainsboro; Frm.Opacity = 0.6; break; } case "ToolClose": { Close(); break; } } } #endregion private void ToolColor_Glass_Click(object sender, EventArgs e) { SetEstate(this, sender); } } } Frm_Main.designer.cs View Code namespace MouseThroughForm { partial class Frm_Main { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Frm_Main)); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.ToolColor = new System.Windows.Forms.ToolStripMenuItem(); this.ToolColor_Gainsboro = new System.Windows.Forms.ToolStripMenuItem(); this.ToolColor_DarkOrchid = new System.Windows.Forms.ToolStripMenuItem(); this.ToolColor_RoyalBlue = new System.Windows.Forms.ToolStripMenuItem(); this.ToolColor_Gold = new System.Windows.Forms.ToolStripMenuItem(); this.ToolColor_LightGreen = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity_10 = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity_20 = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity_30 = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity_40 = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity_50 = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity_60 = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity_70 = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity_80 = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClarity_90 = new System.Windows.Forms.ToolStripMenuItem(); this.ToolAcquiescence = new System.Windows.Forms.ToolStripMenuItem(); this.ToolClose = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // // notifyIcon1 // this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1; this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon"))); this.notifyIcon1.Text = "notifyIcon1"; this.notifyIcon1.Visible = true; // // contextMenuStrip1 // this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ToolColor, this.ToolClarity, this.ToolAcquiescence, this.ToolClose}); this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Size = new System.Drawing.Size(137, 92); // // ToolColor // this.ToolColor.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ToolColor_Gainsboro, this.ToolColor_DarkOrchid, this.ToolColor_RoyalBlue, this.ToolColor_Gold, this.ToolColor_LightGreen}); this.ToolColor.Name = "ToolColor"; this.ToolColor.Size = new System.Drawing.Size(136, 22); this.ToolColor.Text = "颜色设置"; // // ToolColor_Gainsboro // this.ToolColor_Gainsboro.Name = "ToolColor_Gainsboro"; this.ToolColor_Gainsboro.Size = new System.Drawing.Size(100, 22); this.ToolColor_Gainsboro.Tag = "1"; this.ToolColor_Gainsboro.Text = "玻璃"; this.ToolColor_Gainsboro.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolColor_DarkOrchid // this.ToolColor_DarkOrchid.Name = "ToolColor_DarkOrchid"; this.ToolColor_DarkOrchid.Size = new System.Drawing.Size(100, 22); this.ToolColor_DarkOrchid.Tag = "2"; this.ToolColor_DarkOrchid.Text = "炫紫"; this.ToolColor_DarkOrchid.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolColor_RoyalBlue // this.ToolColor_RoyalBlue.Name = "ToolColor_RoyalBlue"; this.ToolColor_RoyalBlue.Size = new System.Drawing.Size(100, 22); this.ToolColor_RoyalBlue.Tag = "3"; this.ToolColor_RoyalBlue.Text = "海洋"; this.ToolColor_RoyalBlue.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolColor_Gold // this.ToolColor_Gold.Name = "ToolColor_Gold"; this.ToolColor_Gold.Size = new System.Drawing.Size(100, 22); this.ToolColor_Gold.Tag = "4"; this.ToolColor_Gold.Text = "金属"; this.ToolColor_Gold.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolColor_LightGreen // this.ToolColor_LightGreen.Name = "ToolColor_LightGreen"; this.ToolColor_LightGreen.Size = new System.Drawing.Size(100, 22); this.ToolColor_LightGreen.Tag = "5"; this.ToolColor_LightGreen.Text = "翠绿"; this.ToolColor_LightGreen.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClarity // this.ToolClarity.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ToolClarity_10, this.ToolClarity_20, this.ToolClarity_30, this.ToolClarity_40, this.ToolClarity_50, this.ToolClarity_60, this.ToolClarity_70, this.ToolClarity_80, this.ToolClarity_90}); this.ToolClarity.Name = "ToolClarity"; this.ToolClarity.Size = new System.Drawing.Size(136, 22); this.ToolClarity.Text = "透明度设置"; // // ToolClarity_10 // this.ToolClarity_10.Name = "ToolClarity_10"; this.ToolClarity_10.Size = new System.Drawing.Size(101, 22); this.ToolClarity_10.Tag = "1"; this.ToolClarity_10.Text = "10%"; this.ToolClarity_10.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClarity_20 // this.ToolClarity_20.Name = "ToolClarity_20"; this.ToolClarity_20.Size = new System.Drawing.Size(101, 22); this.ToolClarity_20.Tag = "2"; this.ToolClarity_20.Text = "20%"; this.ToolClarity_20.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClarity_30 // this.ToolClarity_30.Name = "ToolClarity_30"; this.ToolClarity_30.Size = new System.Drawing.Size(101, 22); this.ToolClarity_30.Tag = "3"; this.ToolClarity_30.Text = "30%"; this.ToolClarity_30.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClarity_40 // this.ToolClarity_40.Name = "ToolClarity_40"; this.ToolClarity_40.Size = new System.Drawing.Size(101, 22); this.ToolClarity_40.Tag = "4"; this.ToolClarity_40.Text = "40%"; this.ToolClarity_40.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClarity_50 // this.ToolClarity_50.Name = "ToolClarity_50"; this.ToolClarity_50.Size = new System.Drawing.Size(101, 22); this.ToolClarity_50.Tag = "5"; this.ToolClarity_50.Text = "50%"; this.ToolClarity_50.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClarity_60 // this.ToolClarity_60.Name = "ToolClarity_60"; this.ToolClarity_60.Size = new System.Drawing.Size(101, 22); this.ToolClarity_60.Tag = "6"; this.ToolClarity_60.Text = "60%"; this.ToolClarity_60.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClarity_70 // this.ToolClarity_70.Name = "ToolClarity_70"; this.ToolClarity_70.Size = new System.Drawing.Size(101, 22); this.ToolClarity_70.Tag = "7"; this.ToolClarity_70.Text = "70%"; this.ToolClarity_70.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClarity_80 // this.ToolClarity_80.Name = "ToolClarity_80"; this.ToolClarity_80.Size = new System.Drawing.Size(101, 22); this.ToolClarity_80.Tag = "8"; this.ToolClarity_80.Text = "80%"; this.ToolClarity_80.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClarity_90 // this.ToolClarity_90.Name = "ToolClarity_90"; this.ToolClarity_90.Size = new System.Drawing.Size(101, 22); this.ToolClarity_90.Tag = "9"; this.ToolClarity_90.Text = "90%"; this.ToolClarity_90.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolAcquiescence // this.ToolAcquiescence.Name = "ToolAcquiescence"; this.ToolAcquiescence.Size = new System.Drawing.Size(136, 22); this.ToolAcquiescence.Text = "默认效果"; this.ToolAcquiescence.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // ToolClose // this.ToolClose.Name = "ToolClose"; this.ToolClose.Size = new System.Drawing.Size(136, 22); this.ToolClose.Text = "退出"; this.ToolClose.Click += new System.EventHandler(this.ToolColor_Glass_Click); // // Frm_Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Gainsboro; this.ClientSize = new System.Drawing.Size(383, 266); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "Frm_Main"; this.Opacity = 0.6; this.Text = "鼠标穿透窗体"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Load += new System.EventHandler(this.Frm_Main_Load); this.contextMenuStrip1.ResumeLayout(false); this.ResumeLayout(false); } #endregion private System.Windows.Forms.NotifyIcon notifyIcon1; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ToolStripMenuItem ToolColor; private System.Windows.Forms.ToolStripMenuItem ToolClarity; private System.Windows.Forms.ToolStripMenuItem ToolAcquiescence; private System.Windows.Forms.ToolStripMenuItem ToolClose; private System.Windows.Forms.ToolStripMenuItem ToolColor_Gainsboro; private System.Windows.Forms.ToolStripMenuItem ToolColor_DarkOrchid; private System.Windows.Forms.ToolStripMenuItem ToolColor_RoyalBlue; private System.Windows.Forms.ToolStripMenuItem ToolColor_Gold; private System.Windows.Forms.ToolStripMenuItem ToolColor_LightGreen; private System.Windows.Forms.ToolStripMenuItem ToolClarity_10; private System.Windows.Forms.ToolStripMenuItem ToolClarity_20; private System.Windows.Forms.ToolStripMenuItem ToolClarity_30; private System.Windows.Forms.ToolStripMenuItem ToolClarity_40; private System.Windows.Forms.ToolStripMenuItem ToolClarity_50; private System.Windows.Forms.ToolStripMenuItem ToolClarity_60; private System.Windows.Forms.ToolStripMenuItem ToolClarity_70; private System.Windows.Forms.ToolStripMenuItem ToolClarity_80; private System.Windows.Forms.ToolStripMenuItem ToolClarity_90; } }
试试其它关键字
鼠标穿透窗体
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
wifi
贡献的其它代码
(
7
)
.
无刷新倒计时
.
制作半透明渐显窗体
.
制作鼠标穿透窗体
.
评论者ip最后一位用*隐去方法
.
获取北京时间多种方法
.
文件夹加锁
.
WebBrowser 加 上进度条
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3