Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

c# - Is it possible to change the background color of the WebBrowser control before loading content?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...