Drag and Drop: Wie kann ich eine Bitmap vom Explorer in eine PictureBox ziehen.

tass

Mitglied
Hallo zusammen,

Ich habe folgendes Problem, ich möchte z.B. vom Explorer aus eine Bilddatei in eine PictureBox ziehen.
Die PictureBox befindet sich ganznormal auf einer "System.Form".

Wär nett wenn mir jemand helfen könnte oder ein gutes Tutroial kennt.

thx tass
 
Vielen Dank für die Hilfe,

Der Link hat mir geholfen das problem zu lösen.
Hier ein kurzer Auszug meiner Lösung (ist allerdings C++ geschroeben).

Code:
private: System::Void pictureBox1_DragEnter(Object *sender, DragEventArgs *e)
{
	e->Effect = DragDropEffects::Copy;	
}


private: System::Void pictureBox1_DragDrop(Object *sender, DragEventArgs *e)
{
	if (e->Data->GetDataPresent(DataFormats::FileDrop))
	{
		Object *object	= e->Data->GetData(DataFormats::FileDrop);
		Array  *array	= (__try_cast<Array *> (object) );
		String *file	= (__try_cast<String *>(array->GetValue(0)));
			
		this->pictureBox1->Image = new System::Drawing::Bitmap(file);
	}
}

Beide Funktionen sind Event Handels.

Funktion_1 "pictureBox1_DragEnter":

Tritt ein wenn ich die Maus in meine PictureBox bewege und einen Datei mitziehe.
Dort setzt ich die Art des Drag and Drop (glaub ich :)?)



Funktion_2 "pictureBox1_DragDrop":

Tritt ein wenn der Drag and Drop abgeschlossen ist.
Zuerst werden ein paar Typcastings durch geführt, damit ich denn Dateiname des
Bildes bekomme.
Anschliessen wird das Bild geladen.
----------------------------------------------------------------------------------------------------------------


Der Quellcode ist so einfach wie möglich geschrieben und enthält keine Abfragen ob z.B. eine Bilddatei gedroppt wird usw..

mfg Tass
 
Zurück