views:

1405

answers:

2

Hello.

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?

A: 

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
Are you doing the same that I want to do?
VansFannel
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
A: 

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