是否有可能改变WebBrowser控件的背景色加载内容之前? [英] Is it possible to change the background color of the WebBrowser control before loading content?

查看:991
本文介绍了是否有可能改变WebBrowser控件的背景色加载内容之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个经常更新内容的 web浏览器控件的页面。我使用的是黑色背景,但在此之前的 web浏览器加载内容的默认颜色是白色。我可以通过加载一个小的HTML字符串设置为黑色,背景改变,但仍有一段时间的 web浏览器显示为白色时,所以有一种形式的。闪烁效应发生

I have a page that contains a WebBrowser control that is frequently updating content. I am using a black background, but the default color before loading content of the WebBrowser is white. I could change it by loading a small HTML string with the background set to black but there is still a period of time when the WebBrowser appears as white so there is a sort of a flickering effect happening.

我的问题是:有没有办法更改 web浏览器的底层控制的颜色

My question is this: is there any way to change the color of the underlying control of the WebBrowser?

我已经尝试了一些解决方案,如隐藏 web浏览器,直到内容已经被加载,但没有这些感觉非常优雅,不工作那么好。

I have tried a few solutions such as hiding the WebBrowser until the content has been loaded but none of these feel very elegant and don't work all that well.

推荐答案

我已经想通了的东西,在我的情况下工作。这并不一定是最优雅的,但它能够完成任务。

I've figured out something that works in my case. It's not necessarily the most elegant but it gets the job done.

我设置默认透明度 web浏览器 0。然后,我附上了 LoadCompleted 事件的事件处理程序:

I set the default Opacity of the WebBrowser to 0. Then, I attach an event handler for the LoadCompleted event:

private void browser_Post_LoadCompleted(object sender, NavigationEventArgs e)
{
    browser_Post.Opacity = 1;
}

现在,我打开一个新的HTML页面之前,我设置了透明度返回0所以它隐藏浏览器,而新的HTML被渲染,所以没有背景的闪烁。当HTML加载完成事件将激发和新的HTML页面将显示为预期。

Now, before I load a new HTML page, I set the Opacity back to 0 so it hides the browser while the new HTML is being rendered so there is no flickering of backgrounds. When the HTML is finished loading the event will fire and the new HTML page will be shown as expected.

这篇关于是否有可能改变WebBrowser控件的背景色加载内容之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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