列表框语法上的 WinForms MouseEventHandler

发布于 2024-09-15 04:04:18 字数 741 浏览 8 评论 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;
    }

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱咩 2024-09-22 04:04:18

我差得很远。这有效。

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

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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文