This example:
Code files:
UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Extctrls;typeTmyshape =class(Tshape)protected procedureCmmouseenter (varMessage:tmessage);messageCm_mouseenter;procedureCmmouseleave (varMessage:tmessage);messageCm_mouseleave;End; TForm1 =class(Tform) Panel1:tpanel; Button1:tbutton; Button2:tbutton;procedureButton1Click (Sender:tobject);procedureButton2click (Sender:tobject);End;varForm1:tform1;Implementation{$R *.DFM}procedureTform1.button1click (Sender:tobject);ConstW = -; H = -;varShape:tmyshape;beginShape: = Tmyshape.create (self); Shape. Parent: = Panel1; Shape. Width: = W; Shape. Height: = H; Randomize; Shape. Left: = Random (PANEL1.CLIENTWIDTH-W); Shape. Top: = Random (panel1.clientheight-h); Shape. Brush.color: = Random ($FFFFFF);End;procedureTform1.button2click (Sender:tobject);varI:integer;begin ifPanel1.controlcount =0 ThenExit; Randomize; I: = Random (Panel1.controlcount-1); Panel1.controls[i]. Free;End;{Tmyshape}procedureTmyshape.cmmouseenter (varMessage:tmessage);Consts =' The color value for the current%s is:%.6x ';varWctrl:twincontrol;beginWctrl: = Parent; whileWctrl.hasparent DoWctrl: = wctrl.parent;ifWctrl isTform ThenTform (Wctrl). Caption: = Format (S, [Classname,brush.color]);inherited;End;procedureTmyshape.cmmouseleave (varMessage:tmessage);Consts =' Form1 ';varWctrl:twincontrol;beginWctrl: = Parent; whileWctrl.hasparent DoWctrl: = wctrl.parent;ifWctrl isTform ThenTform (Wctrl). Caption: = s;inherited;End;End.
Http://www.cnblogs.com/del/archive/2008/10/23/1317926.html
Controls Property and Inheritance Tshape class (using Tshape can solve many graphics problems)