WinForm特效之桌面上的遮罩層實現(xiàn)方法
更新時間:2014年09月20日 10:00:12 投稿:shichen2014
這篇文章主要介紹了WinForm特效之桌面上的遮罩層實現(xiàn)方法,是一個非常實用的技巧,需要的朋友可以參考下
本文實例講述了WinForm特效之桌面上的遮罩層實現(xiàn)方法,分享給大家供大家參考之用。具體如下:
這個一個窗體特效,可以幫你了解幾個windows api函數(shù)。
效果:windows桌面上增加一個簡單的遮罩層,其中WS_EX_TRANSPARENT 比較重要,它實現(xiàn)了鼠標(biāo)穿透的功能。
主要功能代碼如下:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication40
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
public static extern long GetWindowLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
public static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);
[DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
private static extern int SetLayeredWindowAttributes(IntPtr Handle, int crKey, byte bAlpha, int dwFlags);
const int GWL_EXSTYLE = -20;
const int WS_EX_TRANSPARENT = 0x20;
const int WS_EX_LAYERED = 0x80000;
const int LWA_ALPHA = 2;
private void Form1_Load(object sender, EventArgs e)
{
this.BackColor = Color.Silver;
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) | WS_EX_TRANSPARENT | WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, 0, 128, LWA_ALPHA );
}
}
}
希望本文所述對大家C#程序設(shè)計的學(xué)習(xí)有所幫助。
相關(guān)文章
C#中把FastReport.Net報表控件的數(shù)據(jù)保存到數(shù)據(jù)庫
這篇文章介紹了在數(shù)據(jù)庫中保存FastReport.Net報表的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06
C# Winform實現(xiàn)導(dǎo)入和導(dǎo)出Excel文件
這篇文章主要為大家詳細(xì)介紹了C# Winform實現(xiàn)導(dǎo)入和導(dǎo)出Excel文件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-12-12
C#利用性能計數(shù)器監(jiān)控網(wǎng)絡(luò)狀態(tài)
這篇文章主要為大家詳細(xì)介紹了C#利用性能計數(shù)器監(jiān)控網(wǎng)絡(luò)狀態(tài)的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01

