ndfweb.cn

VB6之WebBrowser控件登陸界麵作為示例


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



實現代碼:

複製代碼
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网站建设淘宝店 | ICO图标在线生成 | 外贸网站建设 | 联系我们
©2007-2024 NDF Corporation 鲁ICP备08005967号 Sitemap - RSSRSS订阅