c#非矩形窗体

来源:互联网 发布:怎么目测身高知乎 编辑:程序博客网 时间:2024/05/29 04:47
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Drawing.Drawing2D;
  9. namespace WindowsApplication1
  10. {
  11.     public partial class Form3 : Form
  12.     {
  13.         Point downPoint = Point.Empty;
  14.         public Form3()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         void Set()
  19.         {
  20.             Rectangle rect = this.ClientRectangle;
  21.             using (GraphicsPath path = new GraphicsPath())
  22.             {
  23.                 path.AddEllipse(rect);
  24.                 this.Region = new Region(path);
  25.             }
  26.         }
  27.         private void Form3_Load(object sender, EventArgs e)
  28.         {
  29.             Set();
  30.         }
  31.         private void Form3_MouseDown(object sender, MouseEventArgs e)
  32.         {
  33.             if (e.Button != MouseButtons.Left) return;
  34.             downPoint = new Point(e.X, e.Y);
  35.         }
  36.         private void Form3_MouseMove(object sender, MouseEventArgs e)
  37.         {
  38.             if (downPoint == Point.Empty) return;
  39.             Point location = new Point(this.Left + e.X - downPoint.X, this.Top + e.Y - downPoint.Y);
  40.             this.Location = location;
  41.         }
  42.         private void Form3_MouseUp(object sender, MouseEventArgs e)
  43.         {
  44.             if (e.Button != MouseButtons.Left) return;
  45.             downPoint = Point.Empty;
  46.         }
  47.     }
  48. }
原创粉丝点击