Page 1 of 1
Another ColorGrid question
Posted: Mon Mar 14, 2005 11:50 pm
by 9336985
Is it possible to change the pen used to draw the border around specific squares in a colorGrid? I have a grid with 85 columns and 60 rows, filled with colors. Subsequently, I need to "highlight" certain cells - and I think the best way to do this is to change the color of the cell's border? Possible?
Regards,
Rick
Posted: Tue Mar 15, 2005 7:46 am
by Marjan
Hi, Rick.
Not individual cell border. But you can get the same result by manually drawing rectangle over the selected cell in tChart OnAfterDraw event.
Posted: Tue Mar 15, 2005 8:32 pm
by 9336985
OK that's clear - so let's say I want to draw a rectangle around cell [3, 4]. How do I find the coordinates?
Thanks,
Rick
Posted: Wed Mar 16, 2005 7:42 am
by Marjan
Hi, Rick.
You could try using something along these lines:
Code: Select all
function HighlightRect(Series: TCustom3DGridSeries; XInd, ZInd: Integer): TRect;
begin
With Series do
begin
Result.Left := CalcXPos(XInd);
Result.Right := CalcXPos(XInd+1);
Result.Top := GetVertAxis.CalcPosValue(ZValues.Value[GridIndex[XInd+1,ZInd+2]]);
Result.Bottom := GetVertAxis.CalcPosValue(ZValues.Value[GridIndex[XInd+1,ZInd+1]]);
end;
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
var R: TRect;
begin
r := HighlightRect(Series1,3,2);
With Chart1.Canvas, Chart1 do
begin
Brush.Style := bsClear;
Pen.Color := clRed;
Pen.Width := 2;
Inc(R.Left,Pen.Width div 2);
Inc(R.Top,Pen.Width div 2);
ClipRectangle(ChartRect);
Rectangle(R);
UnclipRectangle;
end;
end;
The example does not actually check if XInd and ZInd are inside valid values .. you can add this and extend the code.
Posted: Wed Mar 16, 2005 6:33 pm
by 9336985
Thanks for this. I'll play with it and see what I get.
Regards,
Rick
Posted: Sat Mar 19, 2005 12:01 am
by 9336985
Hi Marjan,
I checked out this code. It almost works with two issues:
1. The calculation of the right coordinate in the HightRect function is returning the same value as left. It seems to need scaling somehow. In the exampe I have if I add 1 thru 3 to XIND it continues to return the same as the left coordinate. If I add 4 to it it returns the correct value. In this case 4 is the number of ticks between values on the X axis.
2. If I change the brush style to bsSolid, and set a color, as in:
brush.style := bsSolid;
brush.Color := clGreen;
I would expect a solid color of green inside the rectangle and a red border. It remains white.
Thnks,
Rick