如何避免windows CE应用程序中的UI闪烁

本文关键字:UI 闪烁 应用程序 何避免 windows CE | 更新日期: 2023-09-27 18:22:18

我正在windows CE 5.0中使用带有visual studio 2008的c#.net开发一个应用程序。我想通过创建用户控件对象在主用户控件中显示一些用户控件。在主用户控件中加载用户控件时,应用程序正在闪烁。

例如,我有一个用户控件,它有一个按钮图像,我想显示这个用户控件的20个按钮。

`protected override void OnPaint(PaintEventArgs e){//base.OnPaint(e);图形gxOff=e.图形;图形g;

        //Paint the string
        Font boldFont = new Font("Tahoma", 8.0F, FontStyle.Bold);
        Color penColor = Color.FromArgb(48, 48, 48);
        StringFormat drawFormat = new StringFormat();
        drawFormat.Alignment = StringAlignment.Center;
        if (m_bmpOffscreen == null) //Bitmap for doublebuffering
        {
            m_bmpOffscreen = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
        }
        g = Graphics.FromImage(m_bmpOffscreen);
        g.Clear(this.BackColor);
        if (!Disabled)
        {
            backgroundImage = unselected_img;
            if (selected)
            {
                backgroundImage = selected_img;
                g.DrawImage(backgroundImage, this.ClientRectangle, new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height), GraphicsUnit.Pixel);
            }
            else
                g.DrawImage(backgroundImage, this.ClientRectangle, new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height), GraphicsUnit.Pixel);
        }
        else
        {
            backgroundImage = disabled_img;
            g.DrawImage(backgroundImage, this.ClientRectangle, new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height), GraphicsUnit.Pixel);
        }
        g.DrawString(this.Content, boldFont, new SolidBrush(penColor), new RectangleF(0, 3, 20, 20), drawFormat);
        gxOff.DrawImage(m_bmpOffscreen, 0, 0);
    }`

请帮助解决这个问题。

提前谢谢。

如何避免windows CE应用程序中的UI闪烁

您的后台缓冲区代码看起来不错,不过我建议您保留Graphics对象。您可以在OnResize中处理和更新它和后缓冲区位图-请确保检查有效的大小。我怀疑您可能看到OnPaintBackground的默认行为闪烁,请尝试覆盖并不对其进行操作。