大家好!在实例011中介绍了通过控件拖动无边框窗体的功能。但是程序调试运行时,为什么没有任何反应呢?窗体根本拖不动。哪位大侠给帮帮忙,谢谢!以下是我的代码,欢迎大家的更正和补充。
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
private int startX;
private int startY;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Button btn1 = sender as Button;
startX = e.X;
startY = e.Y;
}
}
private void btn1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Left+=e.X-startX;
this.Top+=e.Y-startY;
}
}
}
} |