using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Ex01_9
{
    public partial class Form1 : Form
    {
        private Point MousePos;        //记录鼠标指针的坐标
        private bool bMouseDown = false;  //记录鼠标按键是否按下

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            GraphicsPath Mypform1 = new GraphicsPath();      //实例化GraphicsPath
            Point[] Myarray ={                               //定义点数组
                new  Point(230,200),
                new  Point(400,100),
                new  Point(570,200),
                new  Point(500,400),
                new  Point(300,400)      
            };
            Mypform1.AddPolygon(Myarray);
            this.Region = new Region(Mypform1);
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)        
            {
                MousePos.X = -e.X - SystemInformation.FrameBorderSize.Width;
                MousePos.Y = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
                bMouseDown = true;
            }

        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (bMouseDown)
            {
                Point CurrentPos = Control.MousePosition;
                CurrentPos.Offset(MousePos.X, MousePos.Y);
                Location = CurrentPos;
            }

        }

        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            this.Close();      
        }
    }
}
