如何消除黑色背景上的WebBrowser控件中的闪烁? [英] How can I eliminate flickering in a WebBrowser control on a black background?

查看:282
本文介绍了如何消除黑色背景上的WebBrowser控件中的闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:):

我的应用程序以.NET Framework 2.0为目标,我在黑色表单上有一个WebBrowser控件。 表单加载最初隐藏的WebBrowser控件。 在显示表单之前,它会从硬盘驱动器加载带有黑色背景和浅色
文本的HTML文档。  WebBrowser控件在其OnDocumentCompleted事件处理程序中可见,并且仅在检测到具有黑色背景的HTML文档时,从而保持WebBrowser控件隐藏,直到HTML文档完成
加载。 这样做是为了隐藏WebBrowser控件的初始白色背景,但它只能部分工作。 加载大型HTML文档时仍然存在闪烁的元素。

My application targets the .NET Framework 2.0 and I have a WebBrowser control on a black form.  The form loads with the WebBrowser control initially hidden.  Before displaying the form, it loads an HTML document with a black background and light-colored text from the hard drive.  The WebBrowser control is made visible in its OnDocumentCompleted event handler and only if an HTML document with a black background is detected, thus keeping the WebBrowser control hidden until the HTML document has finished loading.  This is done in an attempt to hide the initial white background of the WebBrowser control, but it works only partially.  There is still an element of flickering when a large HTML document is loaded.

我尝试设置WebBrowser的样式属性并重载OnPaintBackground,但无济于事。

I tried setting the WebBrowser's style attributes and overloading OnPaintBackground, but to no avail.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;

namespace TestApp
{
    public partial class BlackWebBrowser : WebBrowser
    {
        public BlackWebBrowser()
            : base()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            this.UpdateStyles();
        }

        public BlackWebBrowser(IContainer container)
            //: base()
        {
            container.Add(this);

            InitializeComponent();
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            this.UpdateStyles();
        }

        protected override void OnNavigating(WebBrowserNavigatingEventArgs e)
        {
            base.OnNavigating(e);
            this.Hide();
        }

        protected override void OnDocumentCompleted(WebBrowserDocumentCompletedEventArgs e)
        {
            base.OnDocumentCompleted(e);
            if (this.Document.BackColor == Color.FromArgb(0, 0, 0))
                this.Show();
        }

        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            pevent.Graphics.Clear(Color.Black);
        }
    }
}

如何消除闪烁?

 

推荐答案


protected override void OnDocumentCompleted(WebBrowserDocumentCompletedEventArgs e)

{

protected override void OnDocumentCompleted(WebBrowserDocumentCompletedEventArgs e)
{

   ;  base.OnDocumentCompleted(e);

    base.OnDocumentCompleted(e);

    if(this.Document.BackColor == Color.FromArgb(0,0,0))

          this.Show();

    if (this.Document.BackColor == Color.FromArgb(0, 0, 0))
         this.Show();

  }

您好,

您已在此处设置了if条件。因此,只有当文档的背景颜色为黑色时,才显示自己。

You have set the if conditions here. so, only if the background color of the document is black, then show itsself.

如果我误入歧途,请告诉我如何测试并将代码放在这里的方式。 我将非常感谢您的帮助! :)

If I misundertand, please show me the way on how to test it and put your code here. I will be appreciate to help you! :)

最好的问候


这篇关于如何消除黑色背景上的WebBrowser控件中的闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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