我在Winforms应用程序中拖放到Picturebox时遇到问题。当我尝试拖放图片时,我得到的图标看起来像this。它似乎没有采用我正在应用于图片框的AllowDrop。所有方法都在设计器中初始化。
这是我表格中的代码:
private void Overlay_Load(object sender, EventArgs e)
{
pbx_OverlayImage.AllowDrop = true;
}
private void pbx_OverlayImage_DragDrop(object sender, DragEventArgs e)
{
MessageBox.Show("YAY");
pbx_OverlayImage.Image = (Bitmap)e.Data.GetData(DataFormats.Bitmap, true);
}
private void pbx_OverlayImage_DragEnter(object sender, DragEventArgs e)
{
// See if this is a copy and the data includes an image.
if (e.Data.GetDataPresent(DataFormats.Bitmap) &&
(e.AllowedEffect & DragDropEffects.Copy) != 0)
{
// Allow this.
e.Effect = DragDropEffects.Copy;
}
else
{
// Don't allow any other drop.
e.Effect = DragDropEffects.None;
}
}
private void pbx_OverlayImage_MouseDown(object sender, MouseEventArgs e)
{
var img = pbx_OverlayImage.Image;
if (img == null) return;
if (DoDragDrop(img, DragDropEffects.Move) == DragDropEffects.Move)
{
pbx_OverlayImage.Image = null;
return;
}
pbx_OverlayImage.DoDragDrop(pbx_OverlayImage.Image,
DragDropEffects.Copy);
}
这是我用来调用表单的代码:
var form = new Overlay {lbl_Title = {Text = txbx_OverlayName.Text}, pbx_OverlayImage = {AllowDrop = true}};
//var form = new test();
form.Show();
非常感谢你的时间。