在显示新选项卡之前,WinForm TabControl选项卡页面的内容不会更新 [英] WinForm TabControl tab page contents does not update until the new tab is shown

查看:539
本文介绍了在显示新选项卡之前,WinForm TabControl选项卡页面的内容不会更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tabcontrol,它允许创建新的选项卡。每个新选项卡上都有一个Web浏览器控件CEFSharp。创建新标签后,不会显示以前打开的标签;

I have a tabcontrol which allows the creation of new tabs. Each new tab has a web browser control CEFSharp on it. When the new tab is created it is not shown the previously opened tab is shown; which is what we want.

但是,新创建的选项卡上的浏览器仅添加到选项卡页面,并且仅部分运行...无法访问

However, the browser on the newly created tab is only added to the tab page, and only partially runs... it does not go to the loading state until the tab page is shown.

这是 Tabpage 创建代码:

private void AddNewBrowser()
        {
            Log("Adding New Tab and Browser");

            UiBrowser browser = new UiBrowser();

            TabPage tp = new TabPage();

            tp.Controls.Add(browser);
            customTabControl1.TabPages.Add(tp);
        }

UiBrowser 是一个包含 CEFSharp 浏览器控件以及一些额外UI的UserControl。

The UiBrowser is a UserControl which contains the CEFSharp Browser Control plus some extra UI.

这是浏览器的启动代码

private void UiBrowser_Load(object sender, EventArgs e)
        {
            Execute();
        }

private void Execute()
        {
            webBrowser = new ChromiumWebBrowser("http://google.co.uk")
            {
                Dock = DockStyle.Fill,
                Text = "Loading...",
                Tag = Tag
            };

            webBrowser.TitleChanged += Browser_TitleChanged;
            webBrowser.AddressChanged += Browser_AddressChanged;
            webBrowser.ConsoleMessage += Browser_ConsoleMessage;
            webBrowser.LoadingStateChanged += Browser_LoadingStateChanged;
            webBrowser.StatusMessage += Browser_StatusMessage;

            browserPanel.Controls.Add(webBrowser);
            Application.DoEvents();
        }

为简化起见,代码已简化,我还没有找到解决方案或其他解决此问题的地方。

The code has been simplified for clarity and I have not found a solution on SO or elsewhere for this problem.

问题:
如何获取浏览器控件以在保持后台的同时加载网页?那就是该控件所在的 TabPage 不会显示给用户。

推荐答案

加载事件仅在控件首次可见时发生:

The Load event will only happen when the control becomes visible the first time:


在控件对控件可见之前发生

Occurs before the control becomes visible for the first time.

所以尝试将Execute方法移到UserControl的构造函数代码中。

so try moving your Execute method into the UserControl's constructor code.

这篇关于在显示新选项卡之前,WinForm TabControl选项卡页面的内容不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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