dotnet drawing api:
[quoted text, click to view] "Blair Bonnett" <blairb@nospam.paradise.net.nz> wrote in message
news:OEaxoqbBFHA.3524@TK2MSFTNGP15.phx.gbl...
> 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?
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.