DragDrop-Kopiereffekte mit PictureBoxes? Wird eine tatsächliche Kopie der Quelldatei erstellt?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 DragDrop-Kopiereffekte mit PictureBoxes? Wird eine tatsächliche Kopie der Quelldatei erstellt?

Post by Anonymous »

Ich versuche gerade, mithilfe von Bildboxen einen einfachen Drag-Drop-Effekt zu erstellen. Es funktioniert einwandfrei; Allerdings versuche ich dann, die Ressourcendatei des Drop-Ziels abzuleiten, um zu wissen, ob es aktiviert oder deaktiviert werden muss.
Der Teil der if-Anweisung funktioniert jedoch nicht. Ich habe mein Bestes getan, die C#-Schnittstelle zu durchsuchen, um zu sehen, was ihre DragDrop-Effekte/Ereignisargumente bewirken, aber ich kann keinen Teil finden, an dem eine Bitmap-Kopie erstellt wird. Ich habe es so gut wie möglich debuggt, bin aber ziemlich ratlos. Entschuldigung für etwaige Codierungsanomalien.
Dieser Code wird kompiliert und ausgeführt, aber die if-Anweisung wird nicht ausgelöst.
Ich hoffe wirklich, dass ich nicht viele Switch-Fälle codieren muss, um das Bild abzuleiten. Das wäre scheiße.
Wie auch immer, hier sind die relevanten Funktionen:

Code: Select all

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;
}

Code: Select all

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 [url=viewtopic.php?t=26065]problem[/url] 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.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post