Silverlight:在 C# 中拖动时控制(边框、网格等)调整大小

发布于 2024-12-10 09:14:03 字数 1074 浏览 0 评论 0原文

我创建了(使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭了丶谁疼 2024-12-17 09:14:03

从此链接中发现我的错误对象定位和布局

现在我使用 Canvas 作为父级。宽度&边框高度和可以在不改变起点的情况下改变网格。

Point offsetParent; 
..... 

private void MouseMoveEvent(object sender, MouseEventArgs e) 
{ 
    if (bIsMouseDown) 
    { 
        ResizeControl(e); 
        offsetParent = e.GetPosition(parentCanvas); //reset offset to current                 
    } 
} 

private void ResizeControl(MouseEventArgs e) 
{ 
    // get current point 
    Point CurPosParent = e.GetPosition(parentCanvas); 

    // 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;  
    border1.Height += diff.Y;   
    grid1.Width += diff.X;  
    grid1.Height += diff.Y;               
} 

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.

Point offsetParent; 
..... 

private void MouseMoveEvent(object sender, MouseEventArgs e) 
{ 
    if (bIsMouseDown) 
    { 
        ResizeControl(e); 
        offsetParent = e.GetPosition(parentCanvas); //reset offset to current                 
    } 
} 

private void ResizeControl(MouseEventArgs e) 
{ 
    // get current point 
    Point CurPosParent = e.GetPosition(parentCanvas); 

    // 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;  
    border1.Height += diff.Y;   
    grid1.Width += diff.X;  
    grid1.Height += diff.Y;               
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文