ARTICLE AD BOX
I'm currently trying to create a simple drag-drop effect using pictureboxes. It works perfectly fine; however, I'm then trying to deduce the drop target's resource file in order to know if it needs to be turned on or off.
However, the if statement portion is not working. I've done my best to trace through the C# interface to see what their DragDrop effects/event arguments do, but I cannot find a part where a bitmap copy is made. I've debugged it as best as I'm able, but I'm rather stumped. Apologies for any coding anomalies.
This code compiles and runs, but the if statement doesn't trigger. I'm really hoping I don't need to code a lot of switch cases to deduce the image. That would suck.
Anyway, here are the relevant functions:
private void drag_MouseDown(object sender, MouseEventArgs e) { // Set parameters for the DoDragDrop method DragDropEffects supportedEffects = DragDropEffects.Copy; var dragPic = ((PictureBox)sender).Image; //MessageBox.Show(((PictureBox)sender).ImageLocation); //it doesn't know its location--however, i'm using resource files so this might be why //MessageBox.Show(dragPic.ToString()); //System.Drawing.Bitmap result //https://stackoverflow.com/questions/16004682/c-sharp-drag-and-drop-from-one-picture-box-into-another //referenced this only for the image stuff; previous code didn't work during testing and I think this is why DragDropEffects dragEffect = ((PictureBox)sender).DoDragDrop(dragPic, supportedEffects); this.Cursor = Cursors.Default; } private void dropTarget_DragDrop(object sender, DragEventArgs e) { if (sender.GetType().ToString() == "System.Windows.Forms.PictureBox") { //the sender is the drop target, not the origin of the image(e. whatever) ((PictureBox)sender).Image = (Image)e.Data.GetData(DataFormats.Bitmap); MessageBox.Show(e.Data.ToString()); //System.Windows.Forms.DataObject //MessageBox.Show(((PictureBox)sender).ImageLocation); //this is blank, but why?? is it a copy? ((PictureBox)sender).BorderStyle = BorderStyle.None; } //needed to reference this for the DataFormats.Bitmap part //https://stackoverflow.com/questions/16004682/c-sharp-drag-and-drop-from-one-picture-box-into-another } private void dropTarget_DragEnter(object sender, DragEventArgs e) { SetDropEffect(e); } private void dropTarget_DragOver(object sender, DragEventArgs e) { SetDropEffect(e); } // later, this is what I'm trying to accomplish: if (pbxStar.Image == Properties.Resources.star_off) pbxStar.Image = Properties.Resources.star; // the problem here is the if statement. Both the drag source and drop source // have access to the resource files as well, so I don't really understand // what's going on and, more importantly, how to fix it.