User controls using previous forms background

I have several user controls on the form, unfortunately, when the form is displayed, the user controls show the previous background of the form, not the current background of the form.

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 to get the current background as the transparency that is displayed, and not against the background of the previous form?

+1
c # winforms user-controls onpaint
source share
2 answers

You need to set the window style - this is a good main article .

+1
source share

It seems that you are overriding the OnPaintBackground method, doing nothing in the background. Since you leave it empty, you probably shouldn't redefine it. What happens when you just let the default OnPaintBackground do its job? Shouldn't I automatically draw the current control background?

PS I have never worked with .Net user settings. I'm just thinking, trying to find a solution to your problem. Forgive me if what I offer is completely disabled ...

+1
source share

All Articles