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

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

问题描述

我有一个包含经常更新内容的 WebBrowser 控件的页面.我使用的是黑色背景,但加载 WebBrowser 内容之前的默认颜色是白色.我可以通过加载一个背景设置为黑色的小 HTML 字符串来更改它,但仍有一段时间 WebBrowser 显示为白色,因此出现了一种闪烁效果.>

我的问题是:有没有办法改变WebBrowser底层控件的颜色?

我尝试了一些解决方案,例如隐藏 WebBrowser 直到内容加载完毕,但这些解决方案都不是很优雅,也不能很好地工作.

解决方案

我找到了适合我的方法.它不一定是最优雅的,但它可以完成工作.

我将 WebBrowser 的默认 Opacity 设置为 0.然后,我为 LoadCompleted 事件附加了一个事件处理程序:

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

现在,在加载新的 HTML 页面之前,我将 Opacity 设置回 0,以便在渲染新 HTML 时隐藏浏览器,因此不会出现背景闪烁.HTML 加载完成后,将触发该事件,并按预期显示新的 HTML 页面.

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.

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

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.

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;
}

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天全站免登陆