0

我有一个文件列表,当我单击每个文件时,我希望它显示图像的预览。我想我有写代码,但我不确定 () 中的内容

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

我希望点击执行此操作

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

1 回答 1

0

我走得很远。这行得通。

        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;
    }
于 2010-08-19T00:57:18.497 回答