请问一个自定义button类的问题
小弟现在写了一个button类,是可移动的button 。代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
namespace WindowsApplication1
{
public class MoveButton : System.Windows.Forms.Button
{
bool moveStart;
Point mousePosition;
public MoveButton()
{
}
protected override void OnMouseDown (System.Windows.Forms.MouseEventArgs mevent)
{
base.OnMouseDown(mevent);
moveStart = true;
mousePosition = mevent.Location;
}
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs mevent)
{
base.OnMouseMove(mevent);
if (moveStart)
{
int movedX, movedY;
movedX = mousePosition.X - mevent.X;
movedY = mousePosition.Y - mevent.Y;
this.Location = new Point(this.Location.X - movedX, this.Location.Y - movedY);
}
}
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs mevent)
{
base.OnMouseUp(mevent);
moveStart = false;
}}
然后在form1内,new了一百个这样的button,代码如下:
public Form1()
{