0

我正在尝试制作一个应用程序,其中有 7 个图片框,并且每次单击时我想拖放一个,然后在表单上移动鼠标。我通过移动表单上的图片框确实做到了一定程度,但我无法保留原始图像。当我拖放一个图片框时,我只想拖放一个副本,而不是表单上的整个图片框。任何帮助将不胜感激。亲切的问候。

    public Form1()
    {
        controller = Controller.getController();
        InitializeComponent();
        this.AllowDrop = true;
        this.pbOR.MouseDown += pbOR_MouseUp;

    }
    private void pbOR_MouseDown(object sender, MouseEventArgs e)
    {
        downPoint = e.Location;
        pbOR.Parent = this;
        pbOR.BringToFront();
    }

    private void pbOR_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            pbOR.Left += e.X - downPoint.X;
            pbOR.Top += e.Y - downPoint.Y;
        }
    }

    private void pbOR_MouseUp(object sender, MouseEventArgs e)
    {
        Control c = GetChildAtPoint(new Point(pbOR.Left - 1, pbOR.Top));
        if (c == null) c = this;
        Point newLoc = c.PointToClient(pbOR.Parent.PointToScreen(pbOR.Location));
        pbOR.Parent = c;
        pbOR.Location = newLoc;
    }
4

0 回答 0