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

推荐订阅源

cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog RSS Feed
宝玉的分享
宝玉的分享
腾讯CDC
博客园_首页
T
Tailwind CSS Blog
月光博客
月光博客
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
SecWiki News
SecWiki News
美团技术团队
P
Privacy International News Feed
H
Help Net Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Know Your Adversary
Know Your Adversary
Y
Y Combinator Blog
D
DataBreaches.Net
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Cyberwarzone
Cyberwarzone
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
S
Schneier on Security
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
Cisco Talos Blog
Cisco Talos Blog
小众软件
小众软件
Forbes - Security
Forbes - Security
D
Docker
T
Tenable Blog
S
Secure Thoughts
雷峰网
雷峰网
S
Security @ Cisco Blogs
T
The Exploit Database - CXSecurity.com
The Cloudflare Blog
博客园 - 【当耐特】
Spread Privacy
Spread Privacy
阮一峰的网络日志
阮一峰的网络日志

博客园 - 爱你的人

从ArcEngine的模板开始 ArcIMS9.3新特性 ArcIMS9.2补丁安装 构建自己的ExtJs 失败 文字布局(TEXT STYLE)标记(TAGS) 表格(TABLE)标记(TAGS) 表单(FORM)标记(TAGS) 表格进阶(TABLE ADVANCED) 多窗口页面(Frames) 页面(PAGE)标记(TAGS) 字体(FONT)标记(TAGS) 图象(IMAGE)标记(TAGS) 会移动的文字(Marquee) 多媒体页面(Alternative Inline Elements) HTML 标记(Tag)的索引(Index) 多线程程序设计之一 C# 函数方法大全+学习笔记 14.PictureBox
16.ListBox and StatusStrip
爱你的人 · 2008-02-25 · via 博客园 - 爱你的人

由于这两个视频所用到的例子相同,所以就合并起来讲。
主要介绍ListBox and StatusStrip两个控件,实现本地显示URL。同时显示进度状态。
1.StatusStrip控件
本控件可以添加split button、processbar、text。而splitbutton又可以添加Menu、CombBox、Text等。
为split button添加单击事件,如果没有选择路径的话,提示输入。
split button代码如下:
private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e)
        {
            if (toolStripTextBox1.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please select the path that contains hyperlinks");
                return;
            }
            string selectedDirectory = toolStripTextBox1.Text;
            backgroundWorker1.RunWorkerAsync(selectedDirectory);
        }
combbox代码如下:
private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (toolStripComboBox1.Text)
            {
                case "My Documents":
                    toolStripTextBox1.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    break;
                case"Desktop":
                    toolStripTextBox1.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    break;
                case"My Favorities":
                    toolStripTextBox1.Text = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
                    break;
                default:
                    toolStripTextBox1.Text = "";
                    break;
            }
        }

Menu代码:
private void toolStripMenuItem1_Click_1(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            toolStripTextBox1.Text = folderBrowserDialog1.SelectedPath;
        }

2.ListBox
显示文件或者其它列表。
3.涉及了backgroundWorker、folderBrowserDialog两个控件
backgroundWorker的WorkReportsProgress选择true。
事件添加代码:

rivate void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] fileList = System.IO.Directory.GetFiles(e.Argument.ToString());
            string statusText = String.Empty;
            int counter = 0;
            int progress = 0;

            foreach (string currentFiles in fileList)
            {
                using (System.IO.StringReader sr = new System.IO.StringReader(currentFiles))
                {
                    string line;
                    line = string.Empty;
                    while (line != null)
                    {
                        line = sr.ReadLine();
                        if (line.StartsWith("URL="))//确定一个字符串是否以传递的字符串开头。返回布尔值
                        {
                            string myValue = line.Substring(4);
                            try
                            {
                                HttpWebRequest mywebRequst = (HttpWebRequest)HttpWebRequest.Create(myValue);
                                HttpWebResponse myWebResponse = (HttpWebResponse)mywebRequst.GetResponse();
                                statusText = String.Format("{0}-{1}", myValue, myWebResponse.StatusDescription);
                            }
                            catch
                            {
                                statusText = String.Format("{0}-{1}", myValue, "404");
                            }
                            break;
                        }
                    }
             
                }

                counter++;
                progress = (counter * 100) / fileList.Length;
                backgroundWorker1.ReportProgress(progress, statusText);
            }
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            listBox1.Items.Add(e.UserState);
            toolStripStatusLabel1.Text = e.UserState.ToString();
            toolStripProgressBar1.Value = e.ProgressPercentage;
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            toolStripStatusLabel1.Text = "Finish";
            toolStripProgressBar1.Value = 0;
        }


4.添加空间
添加命名空间
system.net

posted on 2008-02-25 16:42  爱你的人  阅读(531)  评论()    收藏  举报