2013-07-31 1 views
4

안녕 내가의 WinForm에서 그림 상자를 dragginging하는 코드를 작성이 내 코드입니다 :Windows Forms : 그림 상자 수동 이미지 솔루션 위에 이미지를 드래그합니까?

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); 

      } 

     } 
    } 

내가 PictureBox를 2 동일한 코드를 가지고, 내 질문은 : 나는 두 번째 내 첫 번째 사진을 드래그하고 때 그것은 넘어서서 코드가 제대로 작동하지만 ı 두 번째 그림 상자를 첫 번째 그림 상자로 드래그하는 동안 두 번째 그림 상자가 첫 번째 그림 상자 아래로 이동합니다. 이것에 대한 속성이 있습니까?

답변

3

당신은 BringToFront() 방법을 사용할 수 있습니다 :

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

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

응답에 대한 감사, 내가 Z-INDEX 개념을 배운 후, 먼저 이전 답을보고, 나는 z는 인덱스 정보 backtofront 기능을 발견, 그때로 돌아왔다 ı에 대한 대답은 대답을 발견하고 방금 대답 한 것을 보았습니다 :) Thanks Again :) –

관련 문제