窗体四周添加阴影
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Y.Utils.WindowsUtils.APIUtils;namespace ShadowForm
{
public partial class Form1 : Form
{
private const int CS_DropSHADOW = 0x20000;
private const int GCL_STYLE = (-26); [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(IntPtr hwnd, int nIndex);
public Form1()
{
InitializeComponent();
// 在构造中调用此函数
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
} private void Form1_Load(object sender, EventArgs e)
{ }
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button == MouseButtons.Left)
{
FormStyleAPI.ReleaseCapture();
FormStyleAPI.SendMessage(Handle, FormStyleAPI.WM_NCLBUTTONDOWN, FormStyleAPI.HTCAPTION, 0);
}
}
}
}
评论