views:

35

answers:

1

I have a list of files and when I click on each one I want it to display a preview of the image. I think I have the write code but I'm not sure what goes in the ()

 this.listBox1.MouseUp += new System.Windows.Forms.MouseEventHandler();

I want the click to do this

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // get selected filename
        string curItem = listBox1.SelectedItem.ToString();

        // BitmapImage.UriSource must be in a BeginInit/EndInit block
        BitmapImage myBitmapImage = new BitmapImage();

        myBitmapImage.BeginInit();
        myBitmapImage.UriSource = new Uri(@curItem);
        myBitmapImage.DecodePixelWidth = 200;
        myBitmapImage.EndInit();
        uploadImage.Source = myBitmapImage;
    }
A: 

I was way off. This works.

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        //<============================================================================
        //  Update image preview when file is selected from listBox1  
        //<============================================================================

        // BitmapImage.UriSource must be in a BeginInit/EndInit block
        BitmapImage myBitmapImage = new BitmapImage();
        string curItem = destinationFolder + "\\" + listBox1.SelectedItem.ToString();

        myBitmapImage.BeginInit();
        myBitmapImage.UriSource = new Uri(@curItem);
        myBitmapImage.DecodePixelWidth = 200;
        myBitmapImage.EndInit();
        uploadImage.Source = myBitmapImage;
    }
rd42