在FORMS的界面上有两个按钮(添加事件,注销事件),一个文本框。
注册事件类:
class MoveAll
{
int x = 0;
int y = 0;
bool isDown = false;
Control controls;
public MoveAll(Control control)
{
controls = control;
control.MouseDown += new MouseEventHandler(control_MouseDown);
control.MouseUp += new MouseEventHandler(control_MouseUp);
control.MouseMove += new MouseEventHandler(control_MouseMove);
}
void control_MouseMove(object sender, MouseEventArgs e)
{
this.controls.Cursor = Cursors.SizeAll;
if (isDown)
{
controls.Location = new Point(controls.Left + e.X - x, controls.Top + e.Y - y);
}
}
void control_MouseUp(object sender, MouseEventArgs e)
{
isDown = false;
}
void control_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
isDown = true;
}
}
点击添加按钮,事件为:MoveAll all=new MoveAll(this.TextBox1);
这样,文本框就可以直接在界面上移动。
但是,如果我想释放可以移动文本框的事件,请问,在注销事件的按钮里面应该怎么写?