繁体   English   中英

C#从右到左调整面板大小

[英]C# Resizing a panel from right to left

我花了几个小时在互联网上搜索如何拿起面板并将其从左侧拿起并向左拉。 我找到了许多资源,并尝试根据自己的需要进行更改,但是它总是从左到右进行。 我目前拥有的代码是:

bool allowResize = false;

private void PanelResize_MouseUp(object sender, MouseEventArgs e)
    {
        allowResize = false;            
    }

    private void PanelResize_MouseMove(object sender, MouseEventArgs e)
    {
        if (allowResize)
        {
            FavoritesPanel.Width = PanelResize.Left + e.X;
        }
    }

    private void PanelResize_MouseDown(object sender, MouseEventArgs e)
    {
        allowResize = true;
    }

“ PanelResize”是被推到面板左侧的图片框。 面板为“ FavoritesPanel”。 两者都固定在顶部,底部和右侧。

我的总体问题是,如何更正代码以将面板从右向左拖动?

问题在于,更改某些面板的宽度的默认设置意味着它会通过右侧向右移动的方式增加面板的宽度。 您需要两件事。 这是您要的(调整宽度),其次是只要将整个面板的宽度增加,就需要将整个面板向左侧移动。

我在这里有类似的代码。 我编写了允许您向上滚动面板上方的代码。 因此,我不得不再次做两件事:使面板高度更高,并使整个面板向上移动。 这是我的代码:

public partial class Form1 : Form
{
    private int actualCursorY;
    private int lastCursorY;
    private bool isDragged;

    public Form1()
    {
        InitializeComponent();
    }

    private void barRadPanel_MouseDown(object sender, MouseEventArgs e)
    {
        lastCursorY = PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)).Y;
        isDragged = true;
    }

    private void barRadPanel_MouseUp(object sender, MouseEventArgs e)
    {
        isDragged = false;
    }

    private void barRadPanel_MouseMove(object sender, MouseEventArgs e)
    {
        if (isDragged)
        {
            actualCursorY = PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)).Y;
            mainRadPanel.Location = new Point(mainRadPanel.Location.X, actualCursorY);

            if (lastCursorY != actualCursorY)
            {
                mainRadPanel.Height -= actualCursorY - lastCursorY;
                lastCursorY = actualCursorY;
            }
        }
    }
}

我尝试使用

e.Y

代替

PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)).Y

但它犯了一些错误。

这是它的作用:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM