使用带有跨2个表单链接的按钮和文本框的Web浏览器? [英] Using a Web Browser with a button and text box linked across 2 forms?

查看:92
本文介绍了使用带有跨2个表单链接的按钮和文本框的Web浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一段代码,该代码从我的文本框中获取邮政编码,然后在Bing中为用户搜索该邮政编码,目前所有这些代码都在Form1上并可以正常工作,我希望对此进行改进通过允许用户按下Form1上的按钮,然后Web浏览器出现在Form2中的想法.到目前为止,我试图弄清这一点的尝试失败了,并且想知道是否有人有任何想法.

I have written a piece of a code which takes the postcode from my textbox then searches it within Bing for the user, at the moment all of it is on Form1 and works as it should, I'm looking to improve on the idea by allowing the user to press a button on Form1 then the web browser appearing in Form2. So far my attempts to figure this out have failed and was wondering if anyone had any ideas.

我附上了我的代码的副本,所有代码都可以在一个表单中使用

I have attached a copy of my code which all works within in one Form

Public Class Form1

    Dim Automate As Boolean

    Private Sub BTNMap_Click_1(sender As Object, e As EventArgs) Handles BTNMap.Click
        Automate = True
        WebBrowser1.Navigate("http://www.bing.com")
    End Sub


    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As 

        WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If Automate = True Then Automate = False Else Exit Sub
        Dim txt As HtmlElement = WebBrowser1.Document.GetElementById("q")
        Dim btn As HtmlElement = WebBrowser1.Document.GetElementById("go")

       txt.SetAttribute("value", PostcodeTextBox.Text)
        btn.InvokeMember("click")
    End Sub

End Class

推荐答案

我并不是建议这样做的方法,但这确实是您所提问题的答案:

Not really the way I would advise doing something like this, but this is the answer to the question as you've asked it:

Form1需要包含您的Button和TextBox控件. Form2需要包含WebBrowser控件.

Form1 needs to contain your Button and TextBox controls. Form2 needs to contain the WebBrowser control.

Form1.vb:

Public Class Form1
    Dim Automate As Boolean

    Private Sub BTNMap_Click_1(sender As Object, e As EventArgs) Handles BTNMap.Click
        Automate = True

        Form2.Automate = Automate
        Form2.SearchInput = PostcodeTextBox.Text
        Form2.WebBrowser1.Navigate("http://www.bing.com")
        Form2.Show()
    End Sub
End Class

Form2.vb:

Public Class Form2
    Public Automate As Boolean
    Public SearchInput As String

    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If Automate = True Then Automate = False Else Exit Sub
        Dim txt As HtmlElement = WebBrowser1.Document.GetElementById("q")
        Dim btn As HtmlElement = WebBrowser1.Document.GetElementById("go")

        txt.SetAttribute("value", SearchInput)
        btn.InvokeMember("click")
    End Sub
End Class

这篇关于使用带有跨2个表单链接的按钮和文本框的Web浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆