ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

c# – Windows窗体:图片框手动拖动操作图像解决方案?

2019-06-29 11:51:45  阅读:208  来源: 互联网

标签:c winforms picturebox drag


嗨,我写了一个代码,将在winform中拖动图片框这是我的代码:

   private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
   {

       pictureBox1.Top=(56 * ((pictureBox1.Top + (e.Y - firsty)) / 56) + 3); //this for the correction of location of picture box
       isdragging[0] = false;

    }
     private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
   {
       isdragging[0] = true;
       firstx = e.X;
       firsty = e.Y;
       changeclickingstatus(pictureBox1);//this about my program
       for (sbyte i = 0; i < (sbyte)20; i++)//this about my program
       {
           clickindex[i] = (sbyte)1;//this about my program
       }
       clickindex[0] = (sbyte)0;//this about my program
       dragtop = (sbyte)(pictureBox1.Top/56);//this about my program
       }



        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
       {
       if (isdragging[0])
       {

           if (pictureBox1.Location.Y + (e.Y - firsty) < 0)
           {
               pictureBox1.Top = 0;//these are the limits of dragging

           }
           else if (pictureBox1.Location.Y + (e.Y - firsty) > 290)
           {
               pictureBox1.Top = 290;//these are the limits of dragging

           }
           else
           {



               pictureBox1.Top = pictureBox1.Top + (e.Y - firsty);

           }


           if (pictureBox1.Location.X + (e.X - firstx) < 6)
           {
               pictureBox1.Left = 6;//these are the limits of dragging
           }
           else if (pictureBox1.Location.X + (e.X - firstx) > 280)
           {
               pictureBox1.Left = 280;//these are the limits of dragging
           }
           else
           {
               pictureBox1.Left = pictureBox1.Left + (e.X - firstx);

           }

       }
   }

我有相同的图片框2代码,我的问题是:
当我将我的第一张图片拖到第二张图片时,它会越过它并且代码正常工作,但是当我将第二张图片框拖到第一张图片框时,第二张图片框会在第一张图片框下面!有这个属性吗?

解决方法:

您可以使用BringToFront()方法:

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
    pictureBox1.BringToFront();
    /**/
}

private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
    pictureBox2.BringToFront();
    /**/
}

标签:c,winforms,picturebox,drag
来源: https://codeday.me/bug/20190629/1326084.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有