ndfweb.cn

VB6之WebBrowser控件登陆界面作为示例


2019-09-05 07:30:43 (780)


实现代码:

复制代码
Private WithEvents HtmlDocument As MSHTML.HtmlDocument Private WithEvents HtmlElement As MSHTML.HTMLButtonElement 'code by lichmama from cnblogs.com Private Sub Form_Load() With WebBrowser1
        .Left = 0 .Top = 0 .Navigate "file://C:\Users\Administrator\Desktop\test.html" End With End Sub Private Sub Form_Resize() With WebBrowser1
        .Width = Me.Width
        .Height = Me.Height End With End Sub Private Sub Form_Unload(Cancel As Integer) Set HtmlElement = Nothing Set HtmlDocument = Nothing End Sub Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) With WebBrowser1 'get the HtmlDocument from webbrowser, ' and bind the control of button to [HtmlElement], ' and setup the event handler of [mybutton]'s onclick. Set HtmlDocument = .Document Set HtmlElement = HtmlDocument.getElementById("submit") End With End Sub Private Function HtmlDocument_oncontextmenu() As Boolean '屏蔽右键菜单 HtmlDocument_oncontextmenu = False End Function Private Function HtmlElement_OnClick() As Boolean 'in this section, we can do any operations to current page. ' think about it, if this is a submit button, we could verify the password, whatever. username = HtmlDocument.getElementById("login_username").Value
    password = HtmlDocument.getElementById("login_password").Value
    Debug.Print "your username:", username
    Debug.Print "your password:", password
    HtmlElement_OnClick = False End Function
复制代码


test.html(@http://www.jb51.net/css/97304.html):

 View Code


然后,让我们来看看效果:


了解更多请访问:http://www.ndfweb.cn/news-733.html
  NDF俱乐部
  国际域名注册
  建站咨询
合作伙伴:万网 | 新网 | 新网互联 NDF网站建设淘宝店 | 实用工具 | 外貿網站建設 | 联系我们
©2006-2020 NDF Corporation Sitemap - RSSRSS订阅