WPF中拖动控件,实现位置随意摆放[1]
来源:互联网 发布:柠檬网络电视 编辑:程序博客网 时间:2024/04/30 14:35
一般的拖动程序,都是实现 MouseLeftButtonDown,MouseLeftButtonUp,MouseMove 这三个事件,大多数的情况下,拖动过程中,都是在 MouseMove 这个函数里面设置控件的坐标。
以下的代码,只有一点点的不同,在拖动过程中,原控件还是在原来位置,只是新产生了一个按控件外形生成的阴影图片,然后设置该阴影图片的位置,最后,鼠标离开的时候,设置原控件的位置。。。
以下的代码,只有一点点的不同,在拖动过程中,原控件还是在原来位置,只是新产生了一个按控件外形生成的阴影图片,然后设置该阴影图片的位置,最后,鼠标离开的时候,设置原控件的位置。。。
private void ContainerPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if ((e.ClickCount <= 1) && (sender != e.Source)) { ElementUI source = e.Source as ElementUI; this.SelectedItem = source; NodeUI eui = e.Source as NodeUI; if ((eui != null) && eui.DataSource.CanDrag) { NodeUI nodeUI = (NodeUI) e.Source; Point point = new Point(nodeUI.CenterX, nodeUI.CenterY); this.startPoint = base.ToPlot(e.GetPosition(this)); this.offsetVector = (Vector) (this.startPoint - point); this.CreateDragShade(nodeUI); this.dragShade.CaptureMouse();//阴影捕获鼠标 e.Handled = true; } } } private void ContainerPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (e.ClickCount <= 1) { NodeUI selectedItem = this.SelectedItem as NodeUI; if ((selectedItem != null) && this.dragShade.IsMouseCaptured) { Point point = base.ToPlot(e.GetPosition(this)); double dx = point.X - this.startPoint.X; double dy = point.Y - this.startPoint.Y; Node dataSource = selectedItem.DataSource; if ((dataSource != null) && dataSource.CanDrag) { dataSource.PerformDrag(dx, dy); } } this.dragShade.ReleaseMouseCapture(); this.dragShade.Visibility = Visibility.Hidden; base.Children.Remove(this.dragShade); } } private void ContainerPanel_MouseMove(object sender, MouseEventArgs e) { if ((e.LeftButton == MouseButtonState.Pressed) && this.dragShade.IsMouseCaptured) { Point point = base.ToPlot(e.GetPosition(this)); PlotPanel.SetCenterX(this.dragShade, point.X - this.offsetVector.X); PlotPanel.SetCenterY(this.dragShade, point.Y - this.offsetVector.Y); } } private void CreateDragShade(NodeUI nodeUI) { VisualBrush brush = new VisualBrush(); brush.Stretch = Stretch.Fill; brush.Visual = nodeUI; brush.Opacity = 0.6; this.dragShade.Width = nodeUI.ActualWidth; this.dragShade.Height = nodeUI.ActualHeight; this.dragShade.Stroke = Brushes.Transparent; this.dragShade.Fill = brush; this.dragShade.Stretch = Stretch.Fill; PlotPanel.SetCenterX(this.dragShade, nodeUI.CenterX); PlotPanel.SetCenterY(this.dragShade, nodeUI.CenterY); this.dragShade.Visibility = Visibility.Visible; base.Children.Add(this.dragShade); }
- WPF中拖动控件,实现位置随意摆放[1]
- WPF中拖动控件,实现位置随意摆放[2]
- WPF中拖动控件,实现位置随意摆放
- WPF实现控件拖动
- .net 2003 项目中关于分页与随意摆放控件
- Android 控件随意拖动
- Android自定义控件实现手机摆放位置的校准
- WPF下实现控件的拖动操作
- 【转】android 怎么随意摆放button的位置?
- c# WPF 中图片缩放功能,鼠标拖动位置
- JavaSwing中随意拖动组件
- WPF中动态改变控件显示位置
- 关于相对布局中控件摆放位置的一个需要注意的小地方
- 随意拖动的picturebox服务器控件源码
- 在WPF中的Canvas上实现控件的拖动、缩放
- [.Net码农].NET运行界面上,实现随意拖动控件的方法
- WPF Popup实现拖动
- QT中在界面中任何拖动控件位置
- LockSupport
- SQL Server 2005合并列成字符串 2008-11-07
- 最近升级了Xcode4.2,结果编译之后发现程序的很多地方都不能用,或者出问题,所以结合网友们的情况把遇见的列出来:
- 两段mysql查询解决从DISCUZ X2到PHPWIND8.7的文章迁移
- Android中Activity.onNewIntent(Intent intent) 的用法
- WPF中拖动控件,实现位置随意摆放[1]
- AVC/H264编码教程
- 函数指针和指针函数以及函数指针数组
- JNDI到底是什么,有什么作用
- CentOS防火墙开启、关闭以及开放指定端口
- WPF中拖动控件,实现位置随意摆放[2]
- 元素上下移动
- java学习——如何实现线程之间的通信 ,Condition 的使用
- route-map实现简单的策略路由+浮动静态路由的概念!