本文介绍了picturebox1到picturebox2的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个带有2个图片盒的1个表格的脚本,直到这里一切都很好。



如果你执行下面的代码,你可以看到你可以移动picturebox1也将它放在picturebox2中。现在我希望丢弃的picturebox1可以调整大小,旋转并在picturebox2内移动(一旦由客户端执行)。我环顾四周但找不到这个问题的答案。任何帮助,我将不胜感激,谢谢



Ps;我还必须告诉你,picturebox2有一个图像,它有一个更大的尺寸(892; 502)然后picturebox1(你会看到wen拖动picturebox1它完全重叠picturebox2而这正是我不想要的! ,我想保存picturebox1大小(163; 195))



所以我的目标(如果可能的话)保存相同的大小(picturebox1),一旦拖动调整大小在picturebox2里面,在picturebox2上移动它,改变mouseclic(点击picturebox1它会缩小图像)



这是代码:

I made a script for 1 form with 2 pictureboxes, until here everything is fine.

If you execute the code below, than you can see you can move the picturebox1 and also drop it inside picturebox2. Now i would like that the dropped picturebox1 can be resized, rotated and moved around inside picturebox2 (once executed by client). I have looked around but can not find the answers to this problem. Any help i would appreciate, Thank you

Ps; I have to tell also that the picturebox2 has a image to it has a size much bigger (892; 502) Then picturebox1 (you will see that wen dragging picturebox1 it overlaps the picturebox2 completely And that is just what i don´t want!!, i would like to conserve the picturebox1 size (163; 195))

So my Goal (if possible) conserve the same size (picturebox1), resize it once dragged inside picturebox2 , Move it around on picturebox2, change the mouseclic (wen click on picturebox1 it decreases the image)

Here is the code:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int x = 0;
        int y = 0;
        bool drag = false;

        private void IncreaseSize(PictureBox p, int dt)
        {
            Size size = p.Size;
            size.Height = size.Height + dt;
            size.Width = size.Width + dt;
            p.Size = size;

        }

        private void DecreaseSize(PictureBox p, int dt)
        {
            Size size = p.Size;
            size.Height = size.Height - dt;
            size.Width = size.Width - dt;
            p.Size = size;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox2.AllowDrop = true;
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);
            x = e.X;
            y = e.Y;
            drag = true;
            DecreaseSize(pictureBox1, 5);
           
        
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (drag)
            {
                //position new get
                pictureBox1.Top += e.Y - y;
                pictureBox1.Left += e.X - x;

            }
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            drag = false;
        }

        private void pictureBox2_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }

        private void pictureBox2_DragDrop(object sender, DragEventArgs e)
        {
            pictureBox2.Image = (Image)e.Data.GetData(DataFormats.Bitmap);
            
        }
    }
}

推荐答案


这篇关于picturebox1到picturebox2的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 05:02