Visual Basic 脚本 Web 浏览器控件

发布于 2025-01-02 04:38:16 字数 138 浏览 3 评论 0原文

如何为 Webbrowser 控件创建一个按钮以返回页面而不重新加载页面?

重新加载就是……。像这样,或者?

Webbrowser.GoBack() ??

并且无需重新加载?有可能吗?

谢谢xu!

how can I make a button for a Webbrowser Control to go back a page without reloading the page?

With reloading it is sth. like this, or?

Webbrowser.GoBack() ??

And without reloading? Is there a posibility?

Thank xou!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

刘备忘录 2025-01-09 04:38:16

好吧,当您执行 GoBack 时,它已经尝试从计算机本地缓存中检索页面,因此它不会发送部分或完整刷新请求。

在浏览会话期间,WebBrowser 控件和 Windows Internet Explorer 维护会话期间访问的所有网站的历史列表,除非您在使用 Navigate 方法时指定 navNoHistory 标志 - 在这种情况下您将无法返回,因此请通过调用 .CanGoBack 来检查是否可以,因为这将返回 True 或 False,具体取决于是否可以。

或者,您可以使用 CommandStateChange 事件来检查向后导航的启用状态。如果事件的 CSC_NAVIGATEBACK 命令被禁用,则已到达历史列表的开头,并且不应使用 GoBack 方法。

所以基本上 GoBack 方法默认情况下不会执行刷新,但是,如果您想执行刷新,可以执行两种类型的刷新,如果您愿意,我可以告诉您这些,所以请告诉我。另外,如果您还有任何其他问题,或者我可以帮助您解决与此问题或您试图解决的问题有关的任何其他问题,请告诉我。

干杯,很快就和你说话了。

Well, when you do a GoBack, it already tries to retreive the page from your computers local cache, so it doesn't send a partial or a full refresh request.

During a browsing session, the WebBrowser control and Windows Internet Explorer maintain a history list of all Web sites visited during a session, unless you specify the navNoHistory flag when you use the Navigate method - in this case you won't be able to go back, so check to see if you can by calling .CanGoBack as that will return a True or False depending on if it can or can't.

Or, you can use the CommandStateChange event to check the enabled state of backward navigation. If the event's CSC_NAVIGATEBACK command is disabled, the beginning of the history list has been reached, and the GoBack method should not be used.

So basically the GoBack method will not do a Refresh by default, however, if you want to do a refresh, there are 2 types of refreshes you can do, I can tell you about those if you want, so just let me know. Also, let me know if you have any other questions or if there is anything else i can help you with relating to this problem or the problem you were trying to solve.

Cheers, speak to you soon.

沩ん囻菔务 2025-01-09 04:38:16

这是很老的帖子,但这里有一个答案,假设我们有一个带有 webBrowser 控件和按钮的 WPF 表单。请注意,该按钮在 xml 定义中设置为禁用。

<Window x:Class="_my_namespace_.frmShowWebData"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:GISWorkbenchPro3"
        mc:Ignorable="d"
        Title="frmShowWebData" Height="450" Width="800" Topmost="True" WindowStartupLocation="CenterScreen" Cursor="Arrow">

    <DockPanel x:Name="myPanel" Margin="10,24,10,7" HorizontalAlignment="Center" x:FieldModifier="public">
        <WebBrowser x:Name="webBrowser1" DockPanel.Dock="Top" x:FieldModifier="public" Navigated="webBrowser1_Navigated" LoadCompleted="webBrowser1_OnLoadCompleted" Cursor="Arrow" Height="358" Width="780" />
        <Button x:Name="btnBack" Content="Back"  Width="112" Height="35" Click="btnBack_Click" VerticalAlignment="Bottom" HorizontalAlignment="Left" IsEnabled="False" Cursor="Hand" />
    </DockPanel>
</Window>

在表单 xaml.cs 文件中,我们需要捕获事件以根据 webBrowser 控件的状态打开/关闭“后退”按钮。我们还需要跟踪按钮的 IsEnabled 值。因此,为 xaml.cs 文件添加一个名为firstLoad 的私有布尔值。

public frmShowWebData()
{
    firstLoad = true;
    InitializeComponent();
}

private void btnBack_Click(object sender, RoutedEventArgs e)
{
    if (this.webBrowser1.CanGoBack) { this.webBrowser1.GoBack(); }
    else
    {
        this.btnBack.IsEnabled = false;
        CommandManager.InvalidateRequerySuggested();
    }
}

private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
    if (firstLoad)
    { firstLoad = false; }
    else
    {
        this.btnBack.IsEnabled = true;
        CommandManager.InvalidateRequerySuggested();
    }
}

如果用户向前导航,然后多次尝试返回,我们还需要检查并(重新)禁用该按钮。

This is very old post, but here is an answer, assuming we have a WPF form with a webBrowser control and a button. Note the button is set to disabled in the xml definition.

<Window x:Class="_my_namespace_.frmShowWebData"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:GISWorkbenchPro3"
        mc:Ignorable="d"
        Title="frmShowWebData" Height="450" Width="800" Topmost="True" WindowStartupLocation="CenterScreen" Cursor="Arrow">

    <DockPanel x:Name="myPanel" Margin="10,24,10,7" HorizontalAlignment="Center" x:FieldModifier="public">
        <WebBrowser x:Name="webBrowser1" DockPanel.Dock="Top" x:FieldModifier="public" Navigated="webBrowser1_Navigated" LoadCompleted="webBrowser1_OnLoadCompleted" Cursor="Arrow" Height="358" Width="780" />
        <Button x:Name="btnBack" Content="Back"  Width="112" Height="35" Click="btnBack_Click" VerticalAlignment="Bottom" HorizontalAlignment="Left" IsEnabled="False" Cursor="Hand" />
    </DockPanel>
</Window>

In the forms xaml.cs file we need to catch the events to turn the Back button on/off depending on the state of the webBrowser control. We also need to track the IsEnabled value of the button. So for the xaml.cs file add a private bool called firstLoad.

public frmShowWebData()
{
    firstLoad = true;
    InitializeComponent();
}

private void btnBack_Click(object sender, RoutedEventArgs e)
{
    if (this.webBrowser1.CanGoBack) { this.webBrowser1.GoBack(); }
    else
    {
        this.btnBack.IsEnabled = false;
        CommandManager.InvalidateRequerySuggested();
    }
}

private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
    if (firstLoad)
    { firstLoad = false; }
    else
    {
        this.btnBack.IsEnabled = true;
        CommandManager.InvalidateRequerySuggested();
    }
}

We also need to check and (re)disable the button if the user navigates forward, then trys to go back to many times.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文