博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
winform 图片集合
阅读量:4700 次
发布时间:2019-06-09

本文共 1695 字,大约阅读时间需要 5 分钟。

winform利用ImageList控件和ListView控件组合制作图片文件浏览器,见图,比较简单,实现LISTVIEW显示文件夹图片功能。

 

1.选择文件夹功能代码:

folderBrowserDialog1.SelectedPath = textBox2.Text;
if
(
this
.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
 
{
     
if
(
this
.folderBrowserDialog1.SelectedPath.Trim() !=
""
)
         
textBox2.Text =
this
.folderBrowserDialog1.SelectedPath.Trim();
 
}

2.确定按钮代码,当然以下代码也可以写到选择文件夹的浏览按钮中,在此只是为了更能说明问题。

  确定按钮实现从选择的文件夹中把图片文件显示到Listview控件中,见代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
        
if
(textBox2.Text.Trim() ==
""
)
return
;
 
        
imageList1.Images.Clear();
        
listView1.Items.Clear();
        
imageLists.Clear();
            
//刷新Listview
            
bindListView();
 
//下面是方法
    
private
void
bindListView()
    
{
        
DirectoryInfo dir =
new
DirectoryInfo(@textBox2.Text.Trim());
 
        
string
[] files =
new
string
[100];
 
        
string
ext =
""
;
 
        
foreach
(FileInfo d
in
dir.GetFiles())
        
{
            
ext = System.IO.Path.GetExtension(textBox2.Text.Trim() + d.Name);
            
if
(ext ==
".jpg"
|| ext ==
".jpeg"
)
//在此只显示Jpg
            
{
                
imageLists.Add(textBox2.Text.Trim() +
"\\"
+ d.Name);
            
}
        
}
        
for
(
int
i = 0; i < imageLists.Count; i++)
        
{
            
imageList1.Images.Add(System.Drawing.Image.FromFile(imageLists[i].ToString()));
            
listView1.Items.Add(System.IO.Path.GetFileName(imageLists[i].ToString()), i);
            
listView1.Items[i].ImageIndex = i;
            
listView1.Items[i].Name = imageLists[i].ToString();
        
}
 
    
}

  需要事先要在代码里定义:

     List<string> imageLists = new List<string>();

     private string path= Application.StartupPath;

    需要在窗体增加imageList和listview控件,并把ListView控件的LargeImageList设置为imageList1

  ListView控件显示图片的大小可以在imageList1控件中调整ImageSize属性,如果图片失真,可以设置imageList1控件的ColorDepth值为Depth32Bit.

    完成。

 

转自:http://www.cnblogs.com/hfzsjz/p/3929131.html

  

转载于:https://www.cnblogs.com/binghe939/p/6645007.html

你可能感兴趣的文章
mybatis之xml中日期时间段查询的sql语句
查看>>
污染物在线自动监控(监测)系统数据传输标准 (HJ212-2017)-空气质量监测数据包构造...
查看>>
【Python】django模型models的外键关联使用
查看>>
httperf ---linux web站点压力测试
查看>>
JAVA基础知识(五)数据类型转换
查看>>
hdu-5583 Kingdom of Black and White(数学,贪心,暴力)
查看>>
算法与设计模式
查看>>
(4)理解 neutron ml2---port创建流程代码解析
查看>>
python List
查看>>
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.
查看>>
免费资源:Polaris UI套件 + Linecons图标集(AI, PDF, PNG, PSD, SVG)
查看>>
http响应状态码大全
查看>>
C# winform 使用DsoFramer 创建 显示office 文档
查看>>
找工作的一些感悟——前端小菜的成长
查看>>
C#委托和事件的应用Observer模式实例
查看>>
Microsoft Dynamics 365 之 味全食品 项目分享和Customer Engagement新特性分享
查看>>
php重定向http请求
查看>>
codevs1018 单词接龙(DFS)
查看>>
内容分发系统MediaEW:助新闻媒体转投HTML5
查看>>
HTML5 Canvas ( 径向渐变, 升级版的星空 ) fillStyle, createRadialGradient
查看>>