我遇到了我的代碼問題。我試圖在表單上拖放一張圖片,但是當我移動選定的圖片框時,當我離開組框時它會丟失。它只是消失。拖放圖片框消失
public partial class Form1 : Form
{
int x_offset = 0; // any better to do this without having a global variable?
int y_offset = 0;
PictureBox dpb = new PictureBox();
public Form1()
{
InitializeComponent();
this.WindowState = FormWindowState.Maximized;
this.AllowDrop = true;
this.pictureBox1.MouseDown += pictureBox1_MouseDown;
this.pictureBox2.MouseDown += pictureBox2_MouseDown;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
PictureBox me = (PictureBox)sender;
x_offset = e.X;
y_offset = e.Y;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
PictureBox me = (PictureBox)sender;
me.Left = e.X + me.Left - x_offset;
me.Top = e.Y + me.Top - y_offset;
}
}
歡迎來到Stack Overflow!最好總結回答中的鏈接背後的內容,如果鏈接過時,它不會丟失。否則,你的第一個答案很棒。 – michaelb958