picturebox1到picturebox2的问题 [英] picturebox1 to picturebox2 problem

查看:99
本文介绍了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);
            
        }
    }
}

推荐答案

不做任何复杂的操作使用 PictureBox ,即使您可以成功。除了显示一些静态图片之外,这个控件绝对没用。做其他事情是可能的,但是控制不会有帮助,只会浪费你的开发时间并消耗一些额外的资源。另请参阅Wes Aday对问题的评论。



该怎么办?我会告诉你。请查看我过去的答案:

在其中附加图片图片框 [ ^ ],

如何从旧图纸中清除面板 [ ^ ],

在C#中绘制一个矩形 [ ^ ]。



有关图像渲染的详细信息,请看到这些答案:

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ],

如何加快我的vb.net应用程序? [ ^ ],

用C#.net鼠标滚轮缩放图像 [ ^ ](特别是放大)。



-SA
Don't do any complex manipulations with PictureBox, even if you can succeed. This control is absolutely useless for anything except showing some static picture. Doing anything else is possible, but the control won't be helping, will only waste your development time and eat up some extra resources. See also the comment to the question by Wes Aday.

What to do instead? I'll tell you. Please see my past answers:
Append a picture within picturebox[^],
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^].

And for detail of image rendering, please see these answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^],
How to speed up my vb.net application?[^],
Zoom image in C# .net mouse wheel[^] (specifically on zoom).

—SA


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆