|
Owner-drawing
TCommonInspector has an owner-drawing feature that allows to draw the name and value area for each property by OnDrawName and OnDrawValue events:
procedure TForm1.CommonInspector1DrawName(Sender: TObject;
TheIndex: Integer; TheCanvas: TCanvas; TheRect: TRect);
begin
Inc(TheRect.Left,TheIndex*2+4);
DrawText(TheCanvas.Handle,
PChar((Sender as TCommonInspector).Names[TheIndex]),-1,
TheRect,DT_SINGLELINE or DT_VCENTER);
end;
TCommonInspector has two useful methods: DrawPropertyNameDefault and DrawPropertyValueDefault. These methods draw the property name and value using the passed index, canvas and rectangle and can be used for simplification the drawing. The follow example draws the color rectangle at the left side of the area, modifies the canvas settings and rectangle and calls the DrawPropertyNameDefault for drawing the default text:
var
BackColors: array[0..3] of TColor = (clNavy,clMaroon,clGreen,clOlive);
...
procedure TForm1.CommonInspector1DrawName(Sender: TObject;
TheIndex: Integer; TheCanvas: TCanvas; TheRect: TRect);
begin
with Sender as TCommonInspector,TheCanvas,TheRect do
begin
Brush.Color:=BackColors[TheIndex mod 4];
FillRect(Rect(Left+4,Top+4,Left+4+Bottom-Top-8,Bottom-4));
Inc(Left,Bottom-Top-12);
Brush.Style:=bsClear;
DrawPropertyNameDefault(TheCanvas,TheIndex,TheRect);
end;
end;
|