网上查找资料看到的大神讲解。
自己整理记录一下,以便以后用到
封装的函数
#region 画圆角
/// <summary>
/// 设置窗体的圆角矩形
/// </summary>
/// <param name="form">须要设置的窗体</param>
/// <param name="rgnRadius">圆角矩形的半径</param>
public static void SetFormRoundRectRgn(Form form, int rgnRadius=20)
{
int hRgn = 0;
hRgn = Win32.CreateRoundRectRgn(0, 0, form.Width + 1, form.Height + 1, rgnRadius, rgnRadius);
Win32.SetWindowRgn(form.Handle, hRgn, true);
Win32.DeleteObject(hRgn);
}
/// <summary>
/// 设置控件的圆角矩形
/// </summary>
public static void SetCtrlRoundRectRgn(IntPtr handel, int width, int height, int rgnRadius)
{
int hRgn = 0;
hRgn = Win32.CreateRoundRectRgn(0, 0, width + 1, height + 1, rgnRadius, rgnRadius);
Win32.SetWindowRgn(handel, hRgn, true);
Win32.DeleteObject(hRgn);
}
/// <summary>
/// 设置panel控件的圆角
/// </summary>
/// <param name="pnl"></param>
public static void SetPanelRoundRectRgn(Panel pnl, int rgnRadius = 15)
{
//调用上面的第二个函数
SetCtrlRoundRectRgn(pnl.Handle, pnl.Width, pnl.Height, rgnRadius);
}
#endregion