悬疑灵异

自定义控件的拖动牛

//添加事件

useUp += new useEventHandler(agEnd);

useMove += new useEventHandler(agMove);

useDown += new useEventHandler(agBegin);

private Point p1;//拖动前鼠标的屏幕坐标

private Point p2;//拖动后鼠标的屏幕坐标

private bool _isDrag;//是否正在被拖动

private bool _allowDragMove;

/// summary

/// 是否允许被拖动。

/// /summary

public bool AllowDragMove

{

get

{

return this._allowDragMove;

}

set

{

this._allowDragMove = value;

}

}

private void DragBegin(object sender, useEventArgs e)

{

if(tton == ft lowDragMove)

{

this._isDrag = true;

//记录下拖动前的坐标

this.p1 = intToScreen(new Point(e.X, e.Y));

}

}

private void DragEnd(object sender, useEventArgs e)

{

if(tton == ft this._isDrag)

{

this._isDrag = false;

//记录下拖动后的坐标

this.p2 = intToScreen(new Point(e.X, e.Y));

//计算位移

int x = p2.X - p1.X;

int y = p2.Y - p1.Y;

//移动控件位置

ft += x;

p += y;

}

}

private void DragMove(object sender, useEventArgs e)

{

随着时间的推移 if(this._isDrag)

{

//记录下拖动后的坐标

this.p2 = intToScreen(new Point(e.X, e.Y));

//计算位移

int x = p2.X - p1.X;

int y = p2.Y - p1.Y;

//移动控件位置

ft += x;

p += y;

//把拖动后的顶点作为新的拖动前顶点

p1 = p2;

}

}

贺州白癜风治疗哪家好
成都好妇科医院
鹰潭男科医院
友情链接