[C#]将图片从列表视图导出到图片框 [英] [C#] Export picture from listview to picturebox

查看:146
本文介绍了[C#]将图片从列表视图导出到图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
如何将图片从listview(form2)导出到picturebox(在form1中)?

从OP答案中复制到这里

因此,我不知道100%如何做到这一点,我是C#的新手,我需要在学校里使用它,但我从来没有使用过C#...不幸的是.我发现了这样的东西:

Hello,
how to export a picture from listview(form2) to picturebox(in form1) ?

Copied here from answer for OP

So, i don''t know in 100% how do that, i''m new in c# and i need that for school, i never before use the c#...unfortunately. I found something like that:

ListViewItem selection = ListView1.GetItemAt(e.X, e.Y);
// If the user selects an item in the ListView, display
// the image in the PictureBox.
if (selection != null)
{
    PictureBox1.Image = System.Drawing.Image.FromFile(
        selection.SubItems[1].Text);


但这对我不起作用.我知道我要求很多,但是请帮我.


But it doesn''t work for me. I know I ask for a lot, but please, help me.

推荐答案

如果form1打开form2,请执行以下操作:

1.为ItemChecked或ItemSelection更改事件创建一个公共处理程序,并在Form1中对其进行处理.
2. form1中的参数发送器将在ListView中提供有关所选图像的所有信息.使用它在PictureBox中显示它.

如果不是,则:
1.在Form1中具有一个静态(取决于应用程序)属性来表示PictureBox图像.
2.在form2中的用户操作上,设置form1的此属性,然后应设置PictureBox图像.

如果静态属性不适合您的应用程序,请使用Application.OpenForms集合访问Form1的当前实例,然后执行相同的操作.

OP评论后更新:我认为您应该先阅读本书或其他材料.长期以来,我用代码喂您无济于事.
If form1 opens form2, do the following:

1. Create a public handler for the ItemChecked or ItemSelection changed event and handle it in the Form1.
2. The parameter sender in form1 will give all the information about the selected image in the ListView. Use that to show it in the PictureBox.

If not, then:
1. Have a static (depends on the application) property in the Form1 to represent the PictureBox image.
2. On user action in form2, set this property of the form1 which inturn should set the PictureBox image.

If a static property does not suit your application, use Application.OpenForms collection to access the current instance of Form1 and then do same.

Update after OP comment: I think you should go through the book or any other material then. Me spoon-feeding you with the code is not going to help in long run.


下面的示例将帮助您了解如何在ListView上单击子项目.
This below sample will help you to understand how to get the subitem clicked on ListView.sample[^]

For passing from one form to another,you can follow the above steps mentioned.


这篇关于[C#]将图片从列表视图导出到图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆