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

C#从右向左调整面板大小,c#,resize,panel,picturebox,mousemove,C#,Resize,Panel,Picturebox,Mousemove,我花了几个小时在互联网上搜索,想办法把我的面板从左侧抓起,然后向左拉。我找到了很多资料来源,我试着根据我的需要修改它,但它总是从左到右。我目前拥有的代码是: bool allowResize = false; private void PanelResize_MouseUp(object sender, MouseEventArgs e) { allowResize = false; } private void PanelRe

我花了几个小时在互联网上搜索,想办法把我的面板从左侧抓起,然后向左拉。我找到了很多资料来源,我试着根据我的需要修改它,但它总是从左到右。我目前拥有的代码是:

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
但它也犯了一些错误

这就是它所做的:


要拖动“面板调整大小”还是调整“收藏夹面板”的大小。您的最后一个问题指出,您希望拖动面板,但为了做到这一点,您需要设置面板的“Left”属性,而不是宽度。本质上,我使用PanelResize作为拖动操作和FavoritesPanel对象之间的网关。所以,当我拖动PanelResize left FavoritesPanel时,它会跟随它的脚步。但是,如果我要设置面板的“Left”属性,我将如何进行设置?