如何将网址导航到特定网页 [英] how to navigate url to specific web page

查看:80
本文介绍了如何将网址导航到特定网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计....

i创建了一个简单的网页浏览器,带有工具条和网页浏览器以及编写的代码,工作正常。

发生的事情是什么时候我点击主页按钮。它是去了在Internet Explorer中设置的主页...它很好,但我想要的是当我点击主页按钮文本字段时,我以前输入的网址也应该更改,

例如,当我输入www.facebook.com时,它正在导航到Facebook,然后文本框中的文本没有改变,如果我们点击任何按钮,如后退,前进,回家。文本框中的文本应该更改为webbrowser的URL ...

代码是...



hi guys....
i created a simple web browser with a tool strip and web browser and written code and it is working fine and
what happening is when i click on home button. it was going to the home page which was set in internet explorer... it was fine, but what i want is when i click home button the text field, which i used to enter url also should change,
for example when i type www.facebook.com it was navigating to facebook and later onward the text in the text box was not changing and if we click any of the button like back, forward, home. the text in the textbox should be changed resepective to the webbrowser's url...
the code for that is...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace web_browser
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(toolStripTextBox1.Text);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
//here the toolstrip text box should display the previous web page url instead of typed one//
       }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            webBrowser1.GoForward();

//here the toolstrip texbox should display the next page url instead of typed one..

        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            webBrowser1.Refresh();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            webBrowser1.Stop();

        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            webBrowser1.GoHome();
// here the toolstrip textbox should get the url of the home page instead of the typed one//
        }


    }
}

推荐答案

你可以使用 WebBrowser.Navigating Event [ ^ ]并将URL设置为TextBox

you can use WebBrowser.Navigating Event[^] and set the URL to TextBox
public Form1()
{
    InitializeComponent();
    webBrowser1.Navigating += 
    new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
}
private void webBrowser1_Navigating(object sender, 
    WebBrowserNavigatingEventArgs e)
{
    TextBox1.Text =e.Url.ToString();
}


您好,





你可以使用文本框的KeyPress事件进行导航,在按键事件中,如果按键是Enter,您将获得按下了哪个键然后导航到写入的URL



对于KeyPress:< a href =http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=vs.110).aspx> http://msdn.microsoft.com/ en-us / library / system.windows.forms.control.keypress(v = vs.110).aspx [ ^ ]



其次有一个名为OnNavigated的WebBrowser事件,您可以使用它来获取浏览器导航的URL并将其设置为文本框。



Web浏览器事件: http://msdn.microsoft.com /en-us/library/system.windows.forms.web浏览器(v = vs.110).aspx [ ^ ]



OnNavigated:http://msdn.microsoft.com/en-us/library/system.windows。 forms.webbrowser.onnavigated(v = vs.110).aspx [ ^ ]



谢谢
Hi,


You can use KeyPress event of textbox to navigate, on keypress event you will get which key has been pressed if the key is Enter then navigate to written URL

For KeyPress : http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=vs.110).aspx[^]

Second there is a event of WebBrowser named OnNavigated you can use it to get the URL where your browser is navigating and set taht to your textbox.

Web Browser Events : http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser(v=vs.110).aspx[^]

OnNavigated : http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.onnavigated(v=vs.110).aspx[^]

Thanks


这篇关于如何将网址导航到特定网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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