The default color of the Tpanel is stored in DFM, the color of the brush is set in the paint function after reading, and then the entire background is filled

Source: Internet
Author: User

The statement reads as follows:

Tcustompanel =class(Tcustomcontrol)PrivateFfullrepaint:boolean;    Fparentbackgroundset:boolean; procedureCmctl3dchanged (varMessage:tmessage);messagecm_ctl3dchanged; protected    procedureCreateParams (varParams:tcreateparams);Override; procedurePaint;Override; Property color default clbtnface;//Set default color, if not change its color, not stored in DFM PropertyFullrepaint:booleanReadFfullrepaintWriteFfullrepaintdefaultTrue;  PropertyParentcolordefaultFalse; procedureSetparentbackground (Value:boolean);Override;  Public     PropertyParentbackgroundstoredFparentbackgroundset; Constructor Create(aowner:tcomponent);Override; functionGetcontrolsalignment:talignment;Override; End;

When you place a tpanel on a form, you have:

  Object Panel1:tpanel      $      232193153'              Panel1'2      End

The equivalent of this time the color default is Clbtnface. If I change its color in the design period, it will be stored as:

  Object Panel1:tpanel      $      232193153'              Panel1'    Color =   clyellow    2  End

Finally, take a look at its paint function:

procedureTcustompanel.paint;Constalignments:Array[Talignment] ofLongint =(Dt_left, Dt_right, dt_center);varRect:trect;  Topcolor, Bottomcolor:tcolor;  Fontheight:integer;  Flags:longint; procedureadjustcolors (Bevel:tpanelbevel); beginTopcolor:=Clbtnhighlight; ifBevel = bvlowered ThenTopcolor: =Clbtnshadow; Bottomcolor:=Clbtnshadow; ifBevel = bvlowered ThenBottomcolor: =Clbtnhighlight; End;beginRect:=GetClientRect; ifBevelouter <> Bvnone Then  beginadjustcolors (Bevelouter);  Frame3d (Canvas, Rect, Topcolor, Bottomcolor, bevelwidth); End;  Frame3d (Canvas, Rect, color, color, BorderWidth); ifBevelinner <> Bvnone Then  beginadjustcolors (Bevelinner);  Frame3d (Canvas, Rect, Topcolor, Bottomcolor, bevelwidth); End;  withCanvas Do  begin    if  notThemeservices.themesenabledor  notParentbackground Then    beginBrush.color: = color;//This is where the brush is set.    If it is changed to clred, the spot will make the Tpanel into Red FillRect (Rect); End; Brush.style:=bsclear; Font:=Self.font; Fontheight:= TextHeight ('W');  withRect Do    beginTop:= ((Bottom + Top)-fontheight)Div 2; Bottom:= Top +Fontheight; End; Flags:= Dt_expandtabsorDt_vcenterorAlignments[falignment]; Flags:=drawtextbidimodeflags (Flags); DrawText (Handle, PChar (Caption),-1, Rect, Flags); End;End;

The default color of the Tpanel is stored in DFM, the color of the brush is set in the paint function after reading, and then the entire background is filled

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.