Silverlight:在 C# 中拖动时控制(边框、网格等)调整大小
我创建了(使用 C#)一个带有边框和边框的网格。父布局是另一个网格。当我尝试动态调整大小时,它没有给出预期的行为。 我保持边框(带网格)的起始位置(左上)固定并保持不变。仅拖动右下角来调整大小。在鼠标移动事件中,宽度和宽度高度根据当前位置而改变。 1)但是当改变宽度和宽度时它总是改变起点(左上)高度 ? 2)当边框调整大小时,子项(网格)不会相应地改变其尺寸?我找不到任何拉伸方法。但是,如果移动边框,则子网格也会随之移动。
Point offsetParent;
.....
private void MouseMoveEvent(object sender, MouseEventArgs e)
{
if (bIsMouseDown)
{
ResizeControl(e);
offsetParent = e.GetPosition(parentGrid); //reset offset to current
}
}
private void ResizeControl(MouseEventArgs e)
{
// get current point
Point CurPosParent = e.GetPosition(parentGrid);
// current & new position difference
Point diff = new Point(CurPosParent.X - offsetParent.X, CurPosParent.Y - offsetParent.Y);
// keep start point (left-top position) of border fixed
// adjust only width & height of border
border1.Width += diff.X; //changes start point (left-top position) ????
border1.Height += diff.Y;
}
I created (using c#) a grid with border & the parent layout is another grid. When I try to rezise dynamically, it doesn't give the expected behaviour.
I keep the start position (left-top) of border (with grid) fixed & only the right-bottom point is dragged to resize. In the Mouse move event, the width & height are changed depending on the current position.
1) But it always change the start point (left-top) when changing the width & height ?
2) When border get resized the child (grid) doesn't change its dimensions accordingly ? I cann't find any stretching method. But if border is moved, then the child grid moves with it.
Point offsetParent;
.....
private void MouseMoveEvent(object sender, MouseEventArgs e)
{
if (bIsMouseDown)
{
ResizeControl(e);
offsetParent = e.GetPosition(parentGrid); //reset offset to current
}
}
private void ResizeControl(MouseEventArgs e)
{
// get current point
Point CurPosParent = e.GetPosition(parentGrid);
// current & new position difference
Point diff = new Point(CurPosParent.X - offsetParent.X, CurPosParent.Y - offsetParent.Y);
// keep start point (left-top position) of border fixed
// adjust only width & height of border
border1.Width += diff.X; //changes start point (left-top position) ????
border1.Height += diff.Y;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从此链接中发现我的错误对象定位和布局
现在我使用 Canvas 作为父级。宽度&边框高度和可以在不改变起点的情况下改变网格。
Found out my mistake from this link Object Positioning and Layout
Now I use a Canvas as the parent. Width & height of border & grid can be changed without changing the start point.