首先,感谢您阅读本文并花时间尝试帮助我们。 我们目前正在为我们的c#课程制作这个项目,我们不得不自己学习拖拽和拖拽,但我们遇到了问题。
情况: 我们有6个带图像的起始图片盒,我们还有6个带描述的文本框,想法很简单,将它们匹配在一起。但是,如果我们将图像从开始图片框拖到6个答案图片框中的一个,但不小心将其放在表单上,它就会消失。
我们无法找到真正重置'的方法。当图像没有放在图片框中时,图像会回到起始位置。
private void Picture_MouseDown(object sender, MouseEventArgs e)
{
try
{
PictureBox source = (PictureBox)sender;
naam = source.ImageLocation;
source.DoDragDrop(source.Image, DragDropEffects.Move);
source.Image = null;
}
catch (NullReferenceException)
{
try
{
throw new RijException("Picturebox is momenteel leeg.");
}
catch (RijException)
{
}
}
}
private void Picture_DragEnter(object sender, DragEventArgs e)
{
PictureBox source = (PictureBox)sender;
e.Effect = DragDropEffects.Move;
}
private void Picture_DragDrop(object sender, DragEventArgs e)
{
PictureBox source = (PictureBox)sender;
source.Image = (Image)e.Data.GetData(DataFormats.Bitmap);
source.Tag = naam;
}
因此,当我们实际将图像(在拖动时)放在图片框外(在表单中)它会消失,我们需要的是将其重置为起始位置的解决方案,但不知道我们怎么做设法解决这个问题。