C#按鈕拖動窗體

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


namespace WindowsApplication6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
           // this.Cancel = true;
        }


        private void Form1_Load(object sender, EventArgs e)
        {


        }
        private int startX;
        private int startY;


        private void button1_MouseDown(object sender, EventArgs e)
        {       
            if (e.Button == MouseButtons.Left)
            {
                startX = e.X;
                startY = e.Y;
            }


        }
        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Left += e.X - startX;
                this.Top += e.Y - startY;
            }


        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章