有哪些不同的方法可以在不使用水平或垂直对齐设置为左和上的情况下拖动和移动对象
我正在开发一个仪表板应用程序,我希望用户能够调整其图表小部件的大小并将其移动到他们喜欢的位置。我在能够同时移动和调整大小方面遇到了问题。原因是当图表对齐方式设置为以下时:
chart.HorizontalAlignment = HorizontalAlignment.Left;
chart.VerticalAlignment = VerticalAlignment.Top;
...移动将完美地工作,但是调整大小将在不可检测的方向上疯狂。如果我将对齐方式切换为以下内容:
chart.HorizontalAlignment = HorizontalAlignment.Stretch;
chart.VerticalAlignment = VerticalAlignment.Stretch;
...移动将关闭,但调整大小将正常工作。
移动代码如下:
public void chart_MouseMove(object sender, MouseEventArgs e)
{
C1Chart chart = sender as C1Chart;
if (!ModifierKey)
{
if (isMouseCaptured)
{
// Calculate the current position of the object.
double deltaV = e.GetPosition(null).Y - mouseVerticalPosition;
double deltaH = e.GetPosition(null).X - mouseHorizontalPosition;
double newTop = deltaV + (double)chart.Margin.Top;
double newLeft = deltaH + (double)chart.Margin.Left;
// Set new position of object.
chart.Margin = new Thickness(newLeft, newTop, 0, 0);
// Update position global variables.
mouseVerticalPosition = e.GetPosition(null).Y;
mouseHorizontalPosition = e.GetPosition(null).X;
}
}
}
mouseVerticalPosition、mouseHorizontalPosition、isMouseCaptured 在图表鼠标按下事件中分配,ModifierKey 是布尔值,用于判断是否按下任何键盘修饰符以了解是否移动。该代码已从 MSDN 中删除,但我愿意接受替代解决方案。
可以在此处找到调整大小代码(Microsoft 示例) 或此处 (丹尼斯·维卡博客)。这是我的问题:是否有不同的方法来进行拖动和拖动?我没有看到移动或调整大小(装饰类)。或者,有没有办法通过对齐 hack 来使用此代码。
I am developing a Dashboard application where I would like the user to be able to resize and move their chart widgets to where they please. I have had problems with the being able to move and resize at the same time. The reason why is that when the chart alignments are set to the following:
chart.HorizontalAlignment = HorizontalAlignment.Left;
chart.VerticalAlignment = VerticalAlignment.Top;
...the move will work perfectly, however the resize will go crazy in undetectable directions. If I switch the alignments to the following :
chart.HorizontalAlignment = HorizontalAlignment.Stretch;
chart.VerticalAlignment = VerticalAlignment.Stretch;
...the move will be off but the resize will work decently.
The move code is as follows :
public void chart_MouseMove(object sender, MouseEventArgs e)
{
C1Chart chart = sender as C1Chart;
if (!ModifierKey)
{
if (isMouseCaptured)
{
// Calculate the current position of the object.
double deltaV = e.GetPosition(null).Y - mouseVerticalPosition;
double deltaH = e.GetPosition(null).X - mouseHorizontalPosition;
double newTop = deltaV + (double)chart.Margin.Top;
double newLeft = deltaH + (double)chart.Margin.Left;
// Set new position of object.
chart.Margin = new Thickness(newLeft, newTop, 0, 0);
// Update position global variables.
mouseVerticalPosition = e.GetPosition(null).Y;
mouseHorizontalPosition = e.GetPosition(null).X;
}
}
}
The mouseVerticalPosition, mouseHorizontalPosition, isMouseCaptured are assigned in a chart mouse down event and ModifierKey is boolean to tell if any of the keyboard modifiers are pressed to know whether or not to move. This code was taken off of MSDN, but I am open to alternate solutions.
The resize code can be found here(Microsoft Example) or here(Denis Vuyka Blog). Here is my question : Is there different way to do the drag & move or the resizing (Adorner Class) that I am not seeing. Or, is there a way to use this code with an alignment hack.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您研究过 MouseDragElementBehavior 吗?
http://blogs.msdn.com/b /dphill/archive/2009/09/25/blend-behaviors.aspx
Have you looked into the MouseDragElementBehavior?
http://blogs.msdn.com/b/dphill/archive/2009/09/25/blend-behaviors.aspx