如果給C#編寫的窗口邊框加上陰影,將使窗體變得非???,但這需要借助windows的動態鏈接庫(win32 API)來實現,下面就給出了一個小實例來演示一下。
//首先引入相關的命名空間,除最下面的那個之外其余都由程序自動添加
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函數加載,實現窗體邊框陰影效果
}
}
}
通過這個例子你應該熟悉DLL函數的引入方法,當然這些函數你可以查一下相關手冊,看看如何使用。
新聞熱點
疑難解答
圖片精選