Fork me on GitHub

csharp中实现图片拖拽

基于Csharp的属性、动作,添加相关委托操作,实现图相框的拖拽。
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.AllowDrop = true;
            pictureBox2.AllowDrop = true;
            pictureBox3.AllowDrop = true;
            pictureBox1.MouseMove += SenderPB_MouseMove;
            pictureBox3.MouseMove += SenderPB_MouseMove;
        }
        private void SenderPB_MouseMove(object sender, MouseEventArgs e)
        {
            PictureBox thisPB = (PictureBox)sender;
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left && (thisPB.Image != null))
            {
                Bitmap b = new Bitmap(thisPB.Image);
                DragDropEffects eff = ((PictureBox)sender).DoDragDrop(b, DragDropEffects.Copy);
            }
        }
        private void pictureBox2_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }
        private void pictureBox2_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(Bitmap)))
            {
                this.pictureBox2.Image = (Bitmap)e.Data.GetData(typeof(Bitmap));
            }
        }
    }




附件列表

     

    目前方向:图像处理,人工智能
    posted @ 2021-04-20 19:14  jsxyhelu  阅读(29)  评论(0编辑  收藏  举报