0

I'm developing a Windows Mobile 5.0 and above application with .Net Compact Framework 2.0 SP2 with C#.

I'm overriding OnPaint method on a custom messagebox that draw a bitmap that fills the entire form with alpha transparency, and a gradient box with a button and a message over the semi-transparent background.

I'm testing it but it is so slow, so I'm going to use double buffer. I can use double buffer to draw the gradient box and the test, but if I use double buffer with the background bitmap with alpha transparency it doen't paint the alpha transparency. So I only do double buffer with gradient box and message and button. The bacground transparent bitmap is painted directly on e.Graphics.

I wondering if I can save e.Graphics on a bitmap to make all the work and end the OnPaint method drawing to e.Graphics this bitmap that I save it before.

This is my code:

protected override void OnPaint(PaintEventArgs e)
{
    Graphics gxOff;
    gxOff = Graphics.FromImage(bmpOffscreen);

    if (!isOuterBackgroundPainted)
    {
        isOuterBackgroundPainted = true;
        DrawingHelper.DrawAlpha(e.Graphics, outerBackground, 180, 0, 0);
        // Here I don't use double buffer because Alpha Blend doesn't work with double buffer.
        //DrawingHelper.DrawAlpha(gxOff, outerBackground, 180, 0, 0);
    }

    // Draw the gradient box
    GradientFill.Fill(gxOff, rectangle, startColor, endColor, FillDirection.TopToBottom);

    gxOff.DrawString(message, font, brush, textLayoutRectangle);

    e.Graphics.DrawImage(bmpOffscreen, 10, 10);
    base.OnPaint(e);
}

bmpOffscreen: double buffer's bitmap.

Maybe I can get a snapshop of form into bmpOffscreen and then draw semi-transparent background over it, gradient box and text.

Summarizing: I want to use alpha blend with double buffer.

Any advice?

VansFannel
  • 45,055
  • 107
  • 359
  • 626

2 Answers2

0

Exactly how to do this is actually pretty complicated - more complicated than a simple answer here can provide. Take a look at the source for Project Resistance. We have a double-buffered Form and we're painting in a background and controls with a transparency alpha channel.

ctacke
  • 66,480
  • 18
  • 94
  • 155
  • Are you doing the same that I want to do? – VansFannel Nov 30 '09 at 09:36
  • Look at the code. It paints a background, then an image with transparency on top of that. If you want to use transparency and double-buffering, it's the only example I'm aware of. – ctacke Nov 30 '09 at 13:57
0

Here is a way to take a snapshot of an application running on Windows Mobile, without taking the title bar and menu.

This is the picture that I was looking for to start double buffering.

VansFannel
  • 45,055
  • 107
  • 359
  • 626