C# 拖拽窗体移动

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;

namespace _aa
{
public partial class Form1 : Form
{
Point p;
public Form1()
{
InitializeComponent();
}

    private void button1_MouseDown(object sender, MouseEventArgs e)
    {
        p = e.Location;
    }

    private void button1_MouseUp(object sender, MouseEventArgs e)
    {
        p = e.Location;
    }

    private void button1_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
            this.Location = new Point(this.Left + (e.X - p.X), this.Top + (e.Y - p.Y));

    }
}

}

猜你喜欢

转载自blog.csdn.net/qq_30725967/article/details/88745429