microsoft public dotnet framework windowsforms Re Why must I

Reviews
Shared by: Self Esteem
Stats
views:
2
rating:
not rated
reviews:
0
posted:
2/25/2009
language:
English
pages:
0
microsoft.public.dotnet.framework.windowsforms: Re: Why must I paint the form background for an owner−draw contro Re: Why must I paint the form background for an owner−draw control? Source: http://www.tech−archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms/2004−10/0348.html From: Mick Doherty (EXCHANGE#WITH_at_AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com) Date: 10/07/04 Date: Thu, 7 Oct 2004 18:27:10 +0100 when overriding the button control you must also set ControlStyles.Opaque to false. \\\ SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.Opaque, false); this.BackColor = Color.Transparent; /// −− Mick Doherty http://dotnetrix.co.uk/nothing.html "Tim Crews" wrote in message news:MPG.1bcf1ffa3b6521ac989681@news.cox.net... > In article <#G$PlrHrEHA.2136@TK2MSFTNGP14.phx.gbl>, Stoitcho Goutsev > says... > >> Hi Tim, >> > >> >> SetStyle(ControlStyles.UserPaint, true); >> SetStyle(ControlStyles.SupportsTransparentBackColor, true); >> this.BackColor = Color.FromArgb(0,SystemColors.Control); >> > > > Stoitcho: > > Thank you for your response. Unfortunately, this still isn't working > for me. I still get a black background around the owner−drawn control. > > You mentioned that at the native Windows level, this behavior interacts > with the form's WS_CLIPCHILDREN style. Do I need to do something at the Re: Why must I paint the form background for an owner−draw control? 1 microsoft.public.dotnet.framework.windowsforms: Re: Why must I paint the form background for an owner−draw contro > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > form level to accomplish this? I notice that the documentation of the SupportsTransparentBackColor says that this is a "simulated" transparency. I wonder what this implies. If the Windows Forms framework still tries to make an intelligent decision as to where to paint the form background around the child control, this probably means I need to set the owner−drawn button's region so that Windows Forms knows where to paint. Since I currently don't modify the button's region, as far as Windows Forms is concerned, my button still occupies its entire bounding rectangle, so Windows Forms doesn't think it needs to do any painting of the form background. Do you think this is my problem? For various reasons, it will be quite difficult to pre−compute the button's region before the button's OnPaint is called. I should also note that my buttons do not use SystemColors.Control as their background color. All of my buttons are different colors, assigned at design time. I use the assigned BackColor as the face color of the button. So my constructor looks like this: public FancyButton() : base() { // class member variables PenWidth = 1; ButtonPressed = false; // Control styles SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.BackColor = Color.FromArgb(0,this.BackColor); } You can see that I also added "AllPaintingInWmPaint", because of advice I have received elsewhere. This makes no difference to my problem, however. My OnPaint handler does nothing except draw a rounded−corner rectangle, with a drop shadow under it. To repeat myself just in case I miscommunicated the first time: neither the button face nor the shadow of the button face occupies the entire bounding rectangle that was specified for the button at design time. So the area that is within the bounding rectangle but outside the owner−drawn button face / button shadow shape needs to have the form's background. Here is how I am currently handling this problem in the button's OnPaint handler: Rectangle ButtonRectangle = new Rectangle(0,0,Width,Height); if (Parent.BackgroundImage == null) { SolidBrush SolBrush = new SolidBrush (Parent.BackColor); e.Graphics.FillRectangle (SolBrush,ButtonRectangle); } else { // Note: "Bounds" coordinates are relative to parent // form, while ButtonRectangle coordinates are relative // to the button. TextureBrush TexBrush = new TextureBrush Re: Why must I paint the form background for an owner−draw control? 2 microsoft.public.dotnet.framework.windowsforms: Re: Why must I paint the form background for an owner−draw contro > (Parent.BackgroundImage, Bounds); > e.Graphics.FillRectangle (TexBrush,ButtonRectangle); > } > > // Then draw the button face and shadow over this. > > This is the code that is performing very badly if Parent.BackgroundImage > != null. > > Thank you for your time, > > Tim Crews > GECO, Inc. −−− Outgoing mail is certified Virus Free. Checked by AVG anti−virus system (http://www.grisoft.com). Version: 6.0.742 / Virus Database: 495 − Release Date: 19/08/2004 Re: Why must I paint the form background for an owner−draw control? 3

Related docs
premium docs
Other docs by Self Esteem