Erasing a transparent form

sebastianodg

Newcomer
Joined
Sep 17, 2008
Messages
3
Another problem related to transparency..
I need to add an "adobe like" splash screen to my app.
I basically need to show an alpha blended, PNG image with shadows. and non rectangular borders.
After reading a lot of posts in different forums, i decided to override the OnPaintBackground() and OnPaint() methods of the form.
Code:
protected override void OnPaintBackground(PaintEventArgs pevent)
{
}

protected override void OnPaint(PaintEventArgs e)
{
	Image m_imgSplashScreen = Image.FromFile(m_strApplicationFolder + "splash_screen.png");

	Graphics gfxGraphics = e.Graphics;
	gfxGraphics.DrawImage(m_imgSplashScreen, new Rectangle(0, 0, this.Width, this.Height));
}
This code works: it shows the alpha blended bitmap correctly.
The problem is that, if the form needs to repaint, the transparent areas isn't updated correctly and the semi-transparent areas are less transparent.
I guess this happens due of the missing background refresh: the OnPaint() function simply paint the same bitmat without deleting what's already drawn.
Now the question: how can i "delete" the previous drawn bitmap?
Filling all the area with a transparent brush will not work...
Calling Invalidate() will not work..
Thanks to you all!
 
Last edited:
I'm assuming that you are implementing your splash screen by doing a screen capture and painting your splash image over it (showing the result on your form), i.e. ala photoshop, right? You probably ought to cache the screen capture image. Or, better yet, cache the composited image. Once you show your splash screen, whatever was underneath is gone graphics-wise and unless you cache it for later you're missing an essential element for your rendering.

My recommendation for implementing this sort of splash screen is to create a backbuffer (a new System.Drawing.Bitmap), create a Graphics object on the bitmap, take a screen capture (using Graphics.CopyScreen), draw your splash screen image over it using Graphics.Draw and then set that image as your splash screen form's background. The redrawing will take care of itself.

Another thing to consider is that Windows 2000/Xp+ supports for-real alpha blended forms using the "layered windows" feature, but if you take that route you lose support for alpha-blending on older versions of Windows.
 
I'm assuming that you are implementing your splash screen by doing a screen capture and painting your splash image over it (showing the result on your form), i.e. ala photoshop, right? You probably ought to cache the screen capture image. Or, better yet, cache the composited image. Once you show your splash screen, whatever was underneath is gone graphics-wise and unless you cache it for later you're missing an essential element for your rendering.

My recommendation for implementing this sort of splash screen is to create a backbuffer (a new System.Drawing.Bitmap), create a Graphics object on the bitmap, take a screen capture (using Graphics.CopyScreen), draw your splash screen image over it using Graphics.Draw and then set that image as your splash screen form's background. The redrawing will take care of itself.

Another thing to consider is that Windows 2000/Xp+ supports for-real alpha blended forms using the "layered windows" feature, but if you take that route you lose support for alpha-blending on older versions of Windows.

Thanks a lot, marble_eater
I tried and it works but... there are still some problems when the things drawn on background of the splash screen change.
In fact, if they change, they will never be displayed correctly: i just have an "old" copy of that portion of the screen.
I need to update what's contained in the backbuffer but i don't know how.
Grabbing the screen again will not work since now the screen shows my splash...
Any suggestions?
Thanks again, anyway!
 
Grabbing the screen again will not work since now the screen shows my splash...
That is exactly your problem, and there is no easy workaround. Like I said, you could try using "layered windows" to achieve a real alpha-blended form, and it will work perfectly, just not on Windows 98/ME.

If you drag a window underneath the Adobe Photoshop splash screen (I'm using 7.0) you will notice that there is a rectangle around the splash screen that isn't updated. Photoshop uses the exact same method we do. Without using layered windows, there is no escaping the fact that there is ultimately nothing underneath your "transparent" window. We're using sleight of hand and I have no problem accepting that it isn't perfect (neither does adobe).
 
That is exactly your problem, and there is no easy workaround. Like I said, you could try using "layered windows" to achieve a real alpha-blended form, and it will work perfectly, just not on Windows 98/ME.

If you drag a window underneath the Adobe Photoshop splash screen (I'm using 7.0) you will notice that there is a rectangle around the splash screen that isn't updated. Photoshop uses the exact same method we do. Without using layered windows, there is no escaping the fact that there is ultimately nothing underneath your "transparent" window. We're using sleight of hand and I have no problem accepting that it isn't perfect (neither does adobe).

I decided to check for OS version and, if it's Win2K, XP or Vista, i'll use layered windows (that works fine!).
Otherwise i'll use your solution.
Anyway, thanks a lot!
PS Pretty complex for a splash screen, isn't it? :)
 
Back
Top