黑夜的狼

沮丧吗,那就是一种无病呻吟!留恋它就是一种高度近视!目光应该放得更远一点! 别不想飞,只是要一步跨过太平洋!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

#region 拖拽事件
Point mouseOffest;
protected void canvalRoot_MouseLeftButtonDown(object o, MouseButtonEventArgs e)
{
Canvas obj
= o as Canvas;
obj.CaptureMouse();
mouseOffest
= e.GetPosition(obj);
obj.MouseMove
+= new MouseEventHandler(canvalRoot_MouseMove);
obj.MouseLeftButtonUp
+= new MouseButtonEventHandler(obj_MouseLeftButtonUp);
}
protected void obj_MouseLeftButtonUp(object o, MouseButtonEventArgs e)
{
Canvas obj
= o as Canvas;
obj.ReleaseMouseCapture();
Point pointEnd
= e.GetPosition(this.Parent as Canvas);
Canvas.SetLeft(obj, pointEnd.X
- mouseOffest.X);
Canvas.SetTop(obj, pointEnd.Y
- mouseOffest.Y);
obj.MouseMove
-= new MouseEventHandler(canvalRoot_MouseMove);
obj.MouseLeftButtonUp
-= new MouseButtonEventHandler(obj_MouseLeftButtonUp);
}
protected void canvalRoot_MouseMove(object o, MouseEventArgs e)
{
Canvas obj
= o as Canvas;
Point pointNow
= e.GetPosition(this.Parent as Canvas);
Canvas.SetLeft(obj, pointNow.X
- mouseOffest.X);
Canvas.SetTop(obj, pointNow.Y
- mouseOffest.Y);
}
#endregion

这只是基本的拖拽

SL3.0以上,可以实现拖放目标的事件

AllowDrop

DragEnter

DragLeave

DragOver

Drop

posted on 2010-12-14 01:58  anncesky  阅读(251)  评论(0编辑  收藏  举报