poin[4].x = 0;
poin[4].y = Width;
Boolean flag = true;
IntPtr hRgn = CreatePolygonRgn(ref poin[0], 8, 1);
SetWindowRgn(this.Handle, hRgn, ref flag);
this.BackColor = Color.BurlyWood;
}
[StructLayout(LayoutKind.Sequential)]
private struct POINTAPI
{
internal int x;
internal int y;
}
[DllImport("gdi32.dll")]
private static extern IntPtr CreatePolygonRgn(ref POINTAPI lpPoint,int nCount,int nPolyFillMode);
[DllImport("user32.dll")]
private static extern IntPtr SetWindowRgn(IntPtr hWnd,IntPtr hRgn, ref Boolean bRedraw);
//设置窗体显示状态
[DllImport("user32.dll")]
private static extern int SetWindowPos(IntPtr hwnd,int hWndInsertAfter,int x,int y,int cx,int cy,int wFlags);
private void Start_Btn_Click(object sender, EventArgs e)
{//始终显示在前面
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1);
}
private void button1_Click(object sender, EventArgs e)
{
//最小化始终显示在前面
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 0);
}
当然,我们也可以自定义窗体的动作,如按着某个轨迹一定,下面的代码中的BackgroundForm程序中就小试了一下,效果还不错,下面是这些程序的效果图: