views:

198

answers:

2

I have several user drawn controls on a form, unfortunately when the form is shown the user drawn controls are showing the previous forms background rather than the current forms background.

The OnPaint event is very simple, and the OnBackgroundPaint event is empty...

Like this:

    protected override void OnPaint(PaintEventArgs pe)
    {
        pe.Graphics.DrawImageUnscaled(_bmpImage, 0, 0);            
    }

    protected override void OnPaintBackground(PaintEventArgs pevent)
    {
        //Leave empty...
    }

How do I get the current background to be the transparency that is shown, rather than the background of the previous form?

+1  A: 

You need to set the window style - here's a nice basic article.

Phil Reif
Exactly what I was missing. Thanks!
A: 

You seem to be overriding the OnPaintBackground method not do anything about the background. Since you're leaving it empty, you probably shouldn't override it in the first place. What happens when you just let the default OnPaintBackground handler do its job? Shouldn't that automatically draw the current control's background properly?

P.S. I've never worked with custom painting .Net controls. I'm merely speculating in an attempt to help find a solution to your problem. Forgive me if what I'm suggesting is completely off...

Ates Goral