WinForm特效之桌面上的遮罩層實(shí)現(xiàn)方法
本文實(shí)例講述了WinForm特效之桌面上的遮罩層實(shí)現(xiàn)方法,分享給大家供大家參考之用。具體如下:
這個(gè)一個(gè)窗體特效,可以幫你了解幾個(gè)windows api函數(shù)。
效果:windows桌面上增加一個(gè)簡(jiǎn)單的遮罩層,其中WS_EX_TRANSPARENT 比較重要,它實(shí)現(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 );
}
}
}
希望本文所述對(duì)大家C#程序設(shè)計(jì)的學(xué)習(xí)有所幫助。
相關(guān)文章
C#中把FastReport.Net報(bào)表控件的數(shù)據(jù)保存到數(shù)據(jù)庫(kù)
這篇文章介紹了在數(shù)據(jù)庫(kù)中保存FastReport.Net報(bào)表的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
Unity動(dòng)畫(huà)混合樹(shù)實(shí)例詳解
這篇文章主要為大家詳細(xì)介紹了Unity動(dòng)畫(huà)混合樹(shù)實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
c#單例模式(Singleton)的6種實(shí)現(xiàn)
這篇文章主要介紹了c#單例模式(Singleton)的6種實(shí)現(xiàn) ,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-12-12
C# Winform實(shí)現(xiàn)導(dǎo)入和導(dǎo)出Excel文件
這篇文章主要為大家詳細(xì)介紹了C# Winform實(shí)現(xiàn)導(dǎo)入和導(dǎo)出Excel文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12
C#實(shí)現(xiàn)基于任務(wù)的異步編程模式
本文詳細(xì)講解了C#實(shí)現(xiàn)基于任務(wù)的異步編程模式,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
C#利用性能計(jì)數(shù)器監(jiān)控網(wǎng)絡(luò)狀態(tài)
這篇文章主要為大家詳細(xì)介紹了C#利用性能計(jì)數(shù)器監(jiān)控網(wǎng)絡(luò)狀態(tài)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
C#日期格式字符串的相互轉(zhuǎn)換操作實(shí)例分析
這篇文章主要介紹了C#日期格式字符串的相互轉(zhuǎn)換操作,結(jié)合實(shí)例形式分析了C#日期格式字符串的相互轉(zhuǎn)換操作函數(shù)與相關(guān)使用技巧,需要的朋友可以參考下2019-08-08

