当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > WebBrowser应用

ASP.NET
FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用方法
.NET 常用功能和代码小结
在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出
asp.net IList查询数据后格式化数据再绑定控件
asp.net sql存储过程
asp.net 简单实现禁用或启用页面中的某一类型的控件
asp.net(c#)获取内容第一张图片地址的函数
The remote procedure call failed and did not execute的解决办法
ASP.NET 在线文件管理
asp.net 读取并修改config文件实现代码
ASP.NET Cookie 操作实现
asp.net Silverlight中的模式窗体
Silverlight中动态获取Web Service地址
asp.net Silverlight应用程序中获取载体aspx页面参数
asp.net 水晶报表隔行换色实现方法
asp.net 获取Gridview隐藏列的值
手动把asp.net的类生成dll文件的方法
asp.net 使用ObjectDataSource控件在ASP.NET中实现Ajax真分页
动态指定任意类型的ObjectDataSource对象的查询参数
asp.net Md5的用法小结

ASP.NET 中的 WebBrowser应用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 63 ::
收藏到网摘: n/a


网络下载。
程序的主角是一个ActiveX控件:WebBrowser。当然,缺省状态下VB的工具箱中并没有它,我们得手工加入,方法是:右击工具箱,在出现的快捷菜单中选择“部件...”,确保在弹出的对话框中选中“控件”标签,找到Microsoft Internet Controls,在它前面的小框中打钩,然后确定。此时你会发现工具箱中多了两个小图标,其中,地球图标代表的控件正是我们需要的WebBrowser。  由于许多人对WebBrowser控件不是很熟悉,VB的帮助中也没有有关它的内容(反正我没有找到),因此有必要介绍一下它的属性、方法和事件,限于篇幅,我们只涉及程序中用到的:  属性:LocationURL 返回控件显示WEB页面的URL。  方法:Navigate 转移到指定的URL或打开指定HTML文件。  事件:1.DownloadBegin 下载操作开时触发。  2.DownloadComplete 下载操作完成、终止或失败时触发。  3.ProgressChange WebBrowser控件跟踪下载操作的过程,并定期触发此事件。其语法为:Sub WebBrowser_ProgressChange (ByVal Progress As Long, ByVal ProgressMax As Long)。Progress变元是当前已下载的数据总量,ProgressMax变元是将要下载的数据总量。  4.TitleChange 当前文档标题改变时触发  除了WebBrowser控件外,程序还需要一个Label控件:Label1;一个ComboBox控件:combo1,用来显示URL地址;一个StatusBar控件:StatusBar1;一个ProgressBar控件:ProgressBar1,用来显示下载进度(StatusBar控件和ProgressBar控件是ActiveX控件Microsoft Windows Common Controls5.0的成员,加入工具箱的方法同WebBrowser控件),这些控件的属性值都用缺省值。  以下是程序清单:  Option Explicit    Private Sub Form_Load()  Me.Caption =“My Explorer”  Label1.Caption = “URL”  Combo1.Text = “”  Combo1.Top = Label1.Height  Combo1.Left = 0  WebBrowser1.Top = Combo1.Top + Combo1.Height  WebBrowser1.Left = 0  Form_Resize  StatusBar1.Style = sbrSimple  ProgressBar1.ZOrder  End Sub    Private Sub Form_Resize()  On Error GoTo a  Combo1.Width = Form1.Width - 100  WebBrowser1.Width = Combo1.Width  WebBrowser1.Height = Form1.Height - Combo1.Height - 1000  ProgressBar1.Top = Me.Height - StatusBar1.Height - 330  ProgressBar1.Left = 0.25 * StatusBar1.Width  ProgressBar1.Width = 0.75 * Me.Width - 250  a:  End Sub    Private Sub Combo1_Click()  `转到指定网址  WebBrowser1.Navigate Combo1.Text  End Sub    Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)  Dim i As Long  Dim existed As Boolean  If KeyCode = 13 Then  If Left(Combo1.Text, 7) <> “http://”Then  Combo1.Text = “http://”+ Combo1.Text  End If  WebBrowser1.Navigate Combo1.Text  For i = 0 To Combo1.ListCount - 1  If Combo1.List(i) = Combo1.Text Then  existed = True  Exit For  Else  existed = False  End If  Next  If Not existed Then  Combo1.AddItem (Combo1.Text)  End If  End If  End Sub    Private Sub WebBrowser1_DownloadBegin()  `下载开始时状态栏显示“Now Linking...”  StatusBar1.SimpleText = “Now Linking...”  End Sub    Private Sub WebBrowser1_DownloadComplete()  `下载完成时状态栏显示“Link Finished”  StatusBar1.SimpleText = “Link Finished”  ProgressBar1.Value = 0  End Sub    Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long,ByVal ProgressMax As Long)  `下载进行时进度条变化  If ProgressMax = 0 Then Exit Sub  ProgressBar1.Max = ProgressMax  If Progress <> -1 And Progress <= ProgressMax Then  ProgressBar1.Value = Progress  End If  End Sub    Private Sub WebBrowser1_TitleChange(ByVal Text As String)  Combo1.Text = WebBrowser1.LocationURL  End Sub