0

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

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”是面板。两者都固定在顶部、底部和右侧。

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

4

1 回答 1

0

问题是更改某些面板的宽度的默认设置意味着它使面板的宽度更大,右侧移动到正确的方向。你需要两件事。这就是您所拥有的(调整宽度),其次是您需要将整个面板移到左侧,只要您使其宽度更大。

我这里有类似的代码。我编写的代码允许您卷起面板的上侧。所以我不得不再次做两件事:让我的面板更高,并将整个面板向上移动。这是我的代码:

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

但它犯了一些错误。

这就是它的作用:

在此处输入图像描述

于 2019-01-18T07:30:30.127 回答