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

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
Cisco Talos Blog
Cisco Talos Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
美团技术团队
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
月光博客
月光博客
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recorded Future
Recorded Future
I
Intezer
博客园 - 【当耐特】
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
罗磊的独立博客
V
V2EX
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
A
About on SuperTechFans
Scott Helme
Scott Helme
Vercel News
Vercel News
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Recent Announcements
Recent Announcements
Hacker News: Ask HN
Hacker News: Ask HN
C
CERT Recently Published Vulnerability Notes
G
Google Developers Blog
B
Blog
博客园 - 叶小钗
WordPress大学
WordPress大学
博客园 - 聂微东
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
IT之家
IT之家
C
Cybersecurity and Infrastructure Security Agency CISA
P
Palo Alto Networks Blog
小众软件
小众软件
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
AWS News Blog
AWS News Blog

博客园 - 爱你的人

从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)  评论()    收藏  举报