using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data; namespace Example007_用获取路径的方法得到圆形窗体...{ /**//// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form ...{ /**//// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() ...{ // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在InitializeComponent 调用后添加任何构造函数代码 // } /**//// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose(bool disposing) ...{ if (disposing) ...{ if (components != null) ...{ components.Dispose(); } } base.Dispose(disposing); } Windows Form Designer generated code#region Windows Form Designer generated code /**//// <summary> /// 设计器支持所需的方法- 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() ...{ // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); } #endregion /**//// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() ...{ Application.Run(new Form1()); } [System.Runtime.InteropServices.DllImport("gdi32")] private static extern IntPtr BeginPath(IntPtr hdc); [System.Runtime.InteropServices.DllImport("gdi32")] private static extern int SetBkMode(IntPtr hdc, int nBkMode); const int TRANSPARENT = 1; [System.Runtime.InteropServices.DllImport("gdi32")] private static extern IntPtr EndPath(IntPtr hdc); [System.Runtime.InteropServices.DllImport("gdi32")] private static extern IntPtr PathToRegion(IntPtr hdc); [System.Runtime.InteropServices.DllImport("gdi32")] private static extern int Ellipse(IntPtr hdc, int X1, int Y1, int X2, int Y2); [System.Runtime.InteropServices.DllImport("user32")] private static extern IntPtr SetWindowRgn(IntPtr hwnd, IntPtr hRgn, bool bRedraw); [System.Runtime.InteropServices.DllImport("user32")] private static extern IntPtr GetDC(IntPtr hwnd); private void Form1_Load(object sender, System.EventArgs e) ...{ IntPtr dc; IntPtr region; dc = GetDC(this.Handle); BeginPath(dc); //根据路径创建不规则窗体 SetBkMode(dc, TRANSPARENT); //设置为透明模式 Ellipse(dc, 20, 20, 220, 220); EndPath(dc); region = PathToRegion(dc); SetWindowRgn(this.Handle, region, true); } const int WM_NCHITTEST = 0x0084; const int HTCLIENT = 0x0001; const int HTCAPTION = 0x0002; protected override void WndProc(ref System.Windows.Forms.Message m) //窗体拖动 ...{ switch (m.Msg) ...{ case WM_NCHITTEST: base.WndProc(ref m); if (m.Result == (IntPtr)HTCLIENT) m.Result = (IntPtr)HTCAPTION; break; default: base.WndProc(ref m); break; } } }}