如果給C#編寫的窗口邊框加上陰影,將使窗體變得非常酷,但這需要借助windows的動態(tài)鏈接庫(win32 API)來實(shí)現(xiàn),下面就給出了一個(gè)小實(shí)例來演示一下。
//首先引入相關(guān)的命名空間,除最下面的那個(gè)之外其余都由程序自動添加
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace winForm //程序的命名空間
{
public partial class Form1 : Form
{
#region 窗體邊框陰影效果變量申明
const int CS_DropSHADOW = 0x20000;
const int GCL_STYLE = (-26);
//聲明Win32 API
[DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int GetClassLong_r(IntPtr hwnd, int nIndex);
#endregion
public Form1()
{
InitializeComponent();
SetClassLong(this.Handle, GCL_STYLE, GetClassLong_r(this.Handle, GCL_STYLE) | CS_DropSHADOW); //API函數(shù)加載,實(shí)現(xiàn)窗體邊框陰影效果
}
}
}
通過這個(gè)例子你應(yīng)該熟悉DLL函數(shù)的引入方法,當(dāng)然這些函數(shù)你可以查一下相關(guān)手冊,看看如何使用。
新聞熱點(diǎn)
疑難解答
圖片精選