2012-02-02 14 views
-1

私はVisual Studio 2008でC#.netを使用してWindows CE 5.0でアプリケーションを開発しています。 私はユーザーコントロールを作成することによってメインユーザーコントロールにいくつかのユーザーコントロールを表示したいと思います。 メインユーザーコントロールでユーザーコントロールを読み込んでいるときに、アプリケーションがちらつきます。Windows CEアプリケーションでUIがちらつくのを避けるには?

たとえば、1つのボタン画像を持つ1つのユーザーコントロールがあります。このユーザーコントロールの20個のボタンを表示したいとします。

`protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); グラフィックスgxOff = e.Graphics; グラフィックス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); 
    }` 

この問題を解決するにはどうすればよいですか。

ありがとうございます。

+0

ドッキング、パネル、ユーザーコントロールとユーザーコントロールのコントロール用のレイアウトパネルを使用していますか? – Reniuz

+0

私は別のユーザーコントロールでロードしようとしているユーザーコントロールのonpaintイベントのボタンイメージを描画しています – Shilpa

+0

描画コードを表示します。また、私は何かを描画する20のユーザーコントロールを追加すると良い考えではないと思う。 – Reniuz

答えて

0

あなたのバックバッファコードは正常に見えますが、私はあなたのGraphicsオブジェクトを周りに保つことをお勧めします。それを処分し、更新することができますし、バックバッファのビットマップは、OnResizeに - 有効なサイズを確認してください。私はあなたがOnPaintBackgroundのデフォルトの動作からちらつきが見えるかもしれないと思って、オーバーライドして、それをノーオペレーションしてみてください。

関連する問題