all groups > dotnet drawing api > january 2005 >
You're in the

dotnet drawing api

group:

What control is being painted?


Re: What control is being painted? Sean Hederman
1/29/2005 7:50:52 AM
dotnet drawing api:
[quoted text, click to view]

This is by design. The assumption with many controls is that you'd want them
to have the same background as the form. The simplest way to get around this
would be to first set the forms background color to something else (say,
White). You'll see that these controls will automatically "inherit" this
background color, Now change these controls background color explicitly to
the background you want them to have (say, Control). This will stop them
from inheriting the form background.

The other way is to move your background painting code into OnPaint, and
call SetStyle(ControlStyles.AllPaintingInWmPaint | SetStyles.UserPaint |
SetSyles.DoubleBuffer) on your form sometime after it's handle is created. I
call this in OnHandleCreated:
protected override void OnHandleCreated(EventArgs e) {
base.OnHandleCreated(e);

if(IsHandleCreated) {
SetStyle(ControlStyles.AllPaintingInWmPaint | SetStyles.UserPaint |
SetSyles.DoubleBuffer);
}
}

However, this might be overkill for your purposes.

What control is being painted? Blair Bonnett
1/29/2005 5:25:52 PM
Hi all,

Run into a problem I can't find a solution for. I'm writing a C# app
which has a custom background for the form (a gradient). I've
successfully overridden the forms OnPaintBackground(PaintEventArgs
pevent) method to paint the background.

However, it seems that some of the controls on the form (such as the
labels) also call this method and hence get painted with the gradient.
Is there some way I can tell what control (or type of control) is being
painted, so only the form itself gets the background?

Pseudo-code for what I mean:
if(ControlBeingPainted == Form){
paint the gradient background
}
else{
base.OnPaintBackground(pevent);
}

Thanks for any help,
AddThis Social Bookmark Button