【发布时间】:2012-11-08 10:27:11
【问题描述】:
我知道你可以使用表单点击和拖动this 但是说我希望它不使用该代码并使用我自己的,我该怎么做呢?
这是我目前所拥有的:
public partial class Form1 : Form
{
MouseDragFormMove dragForm;
public Form1()
{
InitializeComponent();
dragForm = new MouseDragFormMove(this);
dragForm.AllowMouseDownDrag = true;
}
}
public class MouseDragFormMove
{
private bool _status;
public bool AllowMouseDownDrag
{
get { return _status; }
set { _status = value; }
}
private Form parent;
public MouseDragFormMove(Form self)
{
_status = false;
parent = self;
parent.MouseDown +=new MouseEventHandler(parent_MouseDown);
parent.MouseUp += new MouseEventHandler(parent_MouseUp);
parent.MouseMove +=new MouseEventHandler(parent_MouseMove);
}
public void showPos()
{
MessageBox.Show(parent.Location.X + ", " + parent.Location.Y);
}
private Point CPoint;
private Point MPoint;
private bool isDragging;
private void parent_MouseDown(object sender, MouseEventArgs e)
{
CPoint = parent.Location;
MPoint = getMousePoint(e, CPoint);
isDragging = true;
}
private void parent_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
private void parent_MouseMove(object sender, MouseEventArgs e)
{
CPoint = parent.Location;
MPoint = getMousePoint(e, CPoint);
if (isDragging && _status)
{
parent.Location = MPoint;
}
}
private Point getMousePoint(MouseEventArgs e, Point FP)
{
int x = FP.X + (e.Location.X * 2);
int y = FP.Y + (e.Location.Y * 2);
return new Point(x, y);
}
}
我做错了什么?我无法让它工作。而且,它也会闪烁
【问题讨论】:
-
我认为闪烁很可能是正在重绘的窗口。
标签: c# winforms events mouseevent