WinForm殊效之桌面上的遮罩層完成辦法。本站提示廣大學習愛好者:(WinForm殊效之桌面上的遮罩層完成辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是WinForm殊效之桌面上的遮罩層完成辦法正文
本文實例講述了WinForm殊效之桌面上的遮罩層完成辦法,分享給年夜家供年夜家參考之用。詳細以下:
這個一個窗體殊效,可以幫你懂得幾個windows api函數。
後果:windows桌面上增長一個簡略的遮罩層,個中WS_EX_TRANSPARENT 比擬主要,它完成了鼠標穿透的功效。
重要功效代碼以下:
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#法式設計的進修有所贊助。