2013-10-22 76 views
0

我正試圖將一個groupBox2容器中的pictureBox2移動到另一個groupBox1。 問題是,在該容器中,有另一個pictureBox1,當我將pictureBox2移動到pictureBox1上時,pictureBox2會在其周圍獲得一個白色框。刪除圖片框周圍的白色框?

總而言之,我想將pictureBox2融合到pictureBox1。

這裏是我的代碼結合了鼠標移動,向上和向下的功能:

private void pictureBox2_MouseDown(object sender, MouseEventArgs e) 
    { 
     downPoint = e.Location; 
     pictureBox2.Parent = this; 
     pictureBox2.BringToFront(); 

    } 

    private void pictureBox2_MouseMove(object sender, MouseEventArgs e) 
    { 
     if (e.Button == MouseButtons.Left) 
     { 

      pictureBox2.Left += e.X - downPoint.X; 
      pictureBox2.Top += e.Y - downPoint.Y; 
     } 
    } 

    private void pictureBox2_MouseUp(object sender, MouseEventArgs e) 
    { 
     Control c = GetChildAtPoint(new Point(pictureBox2.Left - 1, pictureBox2.Top)); 

     if (c == null) c = this; 
     Point newLoc = c.PointToClient(pictureBox2.Parent.PointToScreen(pictureBox2.Location)); 
     pictureBox2.Parent = c; 
     pictureBox2.BackColor = Color.Transparent; 
     pictureBox2.Location = newLoc; 

     this.Refresh(); 
     pictureBox2.BringToFront(); 
    } 

我可以在任何地方移動pictureBox2併爲其分配一個父,但我不能把它分配pictureBox1作爲其父母,因爲它只檢測到groupBox2作爲其父母。

任何幫助將不勝感激。 謝謝。 Vincent

+0

我發現它是造成問題的groupBox2。刪除它可以將一個pictureBox放在Form本身的另一個之前。但是,如果有任何解決上述問題,將不勝感激。 –

回答

1

嘗試將PictureBox1.BorderStyle屬性設置爲None