0
votes

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?

2
I don't get it. Don't save e.Graphics (won't work), save the bitmap. Create it when the message text is assigned.Hans Passant
I've updated my question. I think that if I can save Graphics to a bitmap I would use double buffer with it.VansFannel

2 Answers

0
votes

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.

0
votes

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.