Winform WebBrowser加上进度条

图示

 

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 
10 namespace WindowsFormsApplication1
11 {
12     public partial class WebBrowserProgressBar : Form
13     {
14         public WebBrowserProgressBar()
15         {
16             InitializeComponent();
17         }
18 
19         //初始from
20         private void WebBrowserProgressBar_Load(object sender, EventArgs e)
21         {
22             progressBar1.Visible = false;
23         }
24       
25 
26         //加载进度条
27         private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
28         {
29             progressBar1.Visible = true;
30             if ((e.CurrentProgress > 0) && (e.MaximumProgress > 0))
31             {
32                 progressBar1.Maximum = Convert.ToInt32(e.MaximumProgress);
33                 progressBar1.Step = Convert.ToInt32(e.CurrentProgress);
34                 progressBar1.PerformStep();
35             }
36             else if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
37             {
38                 progressBar1.Value = 0;
39                 progressBar1.Visible = false;
40             }
41         }
42 
43         //跳转
44         private void btnGo_Click(object sender, EventArgs e)
45         {
46             if (!string.IsNullOrEmpty(textBox1.Text))
47             {
48                 webBrowser1.Navigate(textBox1.Text);
49             }
50         }
51 
52       
53     }

 

posted @ 2012-08-31 12:51  狄大人  阅读(2539)  评论(1编辑  收藏  举报