| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 928 人关注过本帖
标题:关于查找字符的问题
只看楼主 加入收藏
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
程序代码:
//
//哈,谢谢你,这个程序能用,我用的是VS2008,改了下。
//

using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using namespace FileDownLoad
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private WebClient webDownLoad = new WebClient();

        private void Form1_Load(object sender, EventArgs e)
        {
            this.localPathTxt.Text = @"F:\";
            this.msgLab.Text = "准备就绪";
        }

        private void okBtn_Click(object sender, EventArgs e)
        {
            this.progressBar1.Value = 0;

            if (this.urlTxt.Text == string.Empty)
            {
                return;
            }

            string filePath = this.localPathTxt.Text + "\\" + this.fileNameTxt.Text;

            webDownLoad.DownloadFileCompleted += new AsyncCompletedEventHandler(webDownLoad_DownloadFileCompleted);
            webDownLoad.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webDownLoad_DownloadProgressChanged);
            webDownLoad.DownloadFileAsync(new Uri(this.urlTxt.Text.Trim()), filePath);
        }

        private void openBtn_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.ShowNewFolderButton = true;
            DialogResult dr = fbd.ShowDialog();

            if (dr == DialogResult.OK)
            {
                this.localPathTxt.Text = fbd.SelectedPath;
            }
        }

        private void urlTxt_TextChanged(object sender, EventArgs e)
        {
            string url = this.urlTxt.Text.Trim();
            if (url != string.Empty)
            {
                int index = url.LastIndexOf('/');
                this.fileNameTxt.Text = url.Substring(index + 1, url.Length - index - 1);
            }

        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            webDownLoad.CancelAsync();
            this.msgLab.Text = "下载取消";
            this.progressBar1.Value = 0;
        }

        private void webDownLoad_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            msgLab.Text = string.Format("{0}%",e.ProgressPercentage.ToString("N2"));
            this.progressBar1.Value = e.ProgressPercentage;
        }

        private void webDownLoad_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                msgLab.Text = "下载取消";
                this.progressBar1.Value = 0;
            }
            else
            {
                msgLab.Text = "下载完成";
            }
        }
    }
}

   唯实惟新 至诚致志
2011-06-30 10:33
快速回复:关于查找字符的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032456 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved