临海观潮

个人编程、项目管理经验、感想。

博客园 首页 新随笔 联系 订阅 管理

If you set a background picture for a Winform and add some transparent control on the form. All controls on the form will displayed one by one. The winform displays in very slow speed. I browsed some article and found the solution. Add the following code to override the BackgroundImage property of the winform.

    private Bitmap m_BackgroundBitmap;
    private const int SCREEN_WIDTH = 1024;
    private const int SCREEN_HEIGHT = 768;
    public override Image BackgroundImage
    {
      set
      {
        m_BackgroundBitmap = new Bitmap(SCREEN_WIDTH,SCREEN_HEIGHT,PixelFormat.Format32bppPArgb);
        Graphics g = Graphics.FromImage(m_BackgroundBitmap);
        g.DrawImage(value, 0, 0, m_BackgroundBitmap.Width, m_BackgroundBitmap.Height);
        g.Dispose();
      }

      get
      {
        return m_BackgroundBitmap;
      }
    }

Compile and test the application. Everything is OK. There are an useful article from MSDN which talks about the performance of the Windows Form application. The Figure 5 give the sample code to resolve the problem for the transparent background winform.

Technorati : C#

posted on 2006-09-21 16:01  书生无用  阅读(582)  评论(0编辑  收藏  举报