I am working on a GUI where I have a listbox and a picturebox. The items in the listbox are image file paths. What I want to do is drag the file path from the listbox into the picturebox. When I run the code, nothing happens. Can someone help? Here is the code:
private void listbox1_MouseDown()
{
string imagePath = (string) this.ListBox1.SelectedItem;
}
private void picBox1_MouseUp()
{
if(e.Button == MouseButtons.Left)
{
picBox1.Load(imagePath);
}
imagePath = "";
}
Loading
Hirendra SisodiyaPosted Jul 14, 2010, 1:45 AM
Add this line on form load event
this.pictureBox1.AllowDrop = true;
check sample application for drag and drop with picturebox.
thanks
Please mark as answer if it helps
CherRon McLemorePosted Jul 9, 2010, 9:42 AM
Hirendra SisodiyaPosted Jul 8, 2010, 10:33 AM
use this code:
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
listBox1.DoDragDrop(listBox1.SelectedItem, DragDropEffects.Copy)
}
and
private void picBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void picBox1_DragDrop(object sender, DragEventArgs e)
{
picBox1.Load(e.Data.GetData(DataFormats.Text).ToString());
}
thanks
Please mark as answer if it helps