WPF中如何移动窗体中的控件

jenny_zhang 2008-12-05 03:53:45
怎样才能在窗体中任意移动控件。如:窗体中有Image可以移动到任意位置。windowForm里有属性Offset可以偏移,在WPF中怎样移动image。
会使用到MouseMove,MouseButtonDown事件。

public override void MouseButtonDown(object sender, MouseButtonEventArgs e) {
PlanHomeView planHomeView = GeneralWidgets.PlanView;
if(e.ChangedButton == MouseButton.Right){
if(image == null){
return;
}
planHomeView.RemoveImage(image);
}
else if(e.ChangedButton == MouseButton.Left){
Point location = e.GetPosition(planHomeView.productLayer);
Product product = new Product();
product.Url = "D:\\Noodle\\HomePresenter\\images\\blue-sky.gif";
product.Name = "imageSimple";
image = planHomeView.CreateImage(product);
Canvas.SetLeft(image,location.X);
Canvas.SetTop(image,location.Y);
planHomeView.productLayer.Children.Add(image);
planHomeView.productContainer.Add(product,image);
}
}

public override void MouseMove(object sender, MouseEventArgs e) {
}
...全文
457 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouyongh 2008-12-06
  • 打赏
  • 举报
回复
回复过这个问题,你可以参考

http://topic.csdn.net/u/20081008/16/a8bf47b3-e7b1-4a04-9c49-27b17e9ebf5f.html

Hope helps
king19840811 2008-12-05
  • 打赏
  • 举报
回复
关注帮顶

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧