惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
H
Hacker News: Front Page
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
Microsoft Security Blog
Microsoft Security Blog
N
Netflix TechBlog - Medium
U
Unit 42
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
Google Online Security Blog
Google Online Security Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
T
Tenable Blog
博客园 - 叶小钗
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
量子位
P
Proofpoint News Feed
H
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
宝玉的分享
宝玉的分享
Recorded Future
Recorded Future
The Register - Security
The Register - Security
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
S
Schneier on Security
V
Vulnerabilities – Threatpost
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
G
GRAHAM CLULEY
G
Google Developers Blog
月光博客
月光博客
V
V2EX
T
Troy Hunt's Blog
A
Arctic Wolf

博客园 - semye

input+select(multiple)实现下拉框输入值 简单的js分页脚本 - semye - 博客园 请问做个类似这样的网站多少钱 省份和城市 - semye - 博客园 客户端取用户控件中服务器控件的标识 VS2003调试很慢 enctype="multipart/form-data" 群发邮件太慢了! SQL SERVER “数组参数” WEB水晶报表部署笔记 写程序解智力题,help!!! 低级错误是怎样“炼”成的? SQL语句区分大小写问题 发送邮件 - semye - 博客园 JS事件大全 WinForm程序实现滚动字幕与背景音乐 公历转换为农历 简单水晶报表程序与安装部署文件制作 导数程序
WinForm动态添加控件及其事件
semye · 2007-04-04 · via 博客园 - semye

 1        private void PhotoForm_Load(object sender, System.EventArgs e)
 2        {
 3            this.LoadPhoto();
 4        }

 5        private void LoadPhoto()
 6        {
 7            int  i= 0;
 8            string url = this.GetUrl();
 9            string[] sFiles = System.IO.Directory.GetFiles(url+"\\images\\small\\","*.*");
10            for(i=0;i<sFiles.Length;i++)
11            {
12                this.ViewPhoto(i,sFiles[i].ToString());
13            }

14        }

15        /// <summary>
16        /// 取项目路径
17        /// </summary>
18        /// <returns></returns>

19        private string GetUrl()
20        {
21            string b = Application.StartupPath;
22            int i = b.LastIndexOf("\\");
23            b = b.Substring(0,i);
24            int j = b.LastIndexOf("\\");
25            b = b.Substring(0,j+1);
26            return b; 
27        }

28        /// <summary>
29        /// 加载图片控件
30        /// </summary>
31        /// <param name="i">图片序号</param>
32        /// <param name="filePath">文件名</param>

33        private void ViewPhoto(int i,string filePath)
34        {
35            string name="";
36            name = "image_"+i.ToString();
37            PictureBox pb = new PictureBox();
38            pb.Name = name;
39            pb.Image=System.Drawing.Image.FromFile(filePath);
40            //保存文件名
41            pb.Tag = filePath;
42            this.Controls.Add(pb);
43            pb.Width=128;
44            pb.Height =96;
45            pb.Location = new Point(x,y);
46            x=x+230;
47            if((i+1)%4==0 && i!=0)
48            {
49                x=100;
50                y=y+120;
51            }

52            //添加事件
53            pb.Click += new System.EventHandler(picture_Click);
54
55        }
    
56        private void picture_Click(object sender, System.EventArgs e)
57        {
58            PictureBox pb = (PictureBox)sender;
59            string name = pb.Name;
60            string path = pb.Tag.ToString();
61        }

62