I have three StringGrids (sgInvoice, sgPreview, sgUpdate)and am using the same OnDrawCell event for each StringGrid. Can I possibly have one block of code which is used for the OnDrawCell event for all the StringGrids?
Here is my code for the OnDrawCell event. It is identical to the other StringGrids (sgPreview, sgUpdate).
Thanks in advance.
------------------------------------
There's no place like 127.0.0.1
------------------------------------
Here is my code for the OnDrawCell event. It is identical to the other StringGrids (sgPreview, sgUpdate).
Thanks in advance.
Code:
procedure TfrmMain.sgInvoiceDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
S: String;
drawrect :trect;
begin
//paint column backcolour
Case ACol of
3:
begin
sgInvoice.Canvas.Brush.Color := clCream; //clBtnFace;
sgInvoice.Canvas.FillRect(Rect);
sginvoice.Canvas.Font.Color := clBlack;
sgInvoice.Canvas.TextOut(Rect.Left + 2 , Rect.Top + 2, sgInvoice.Cells[ACol, ARow]);
end;
4:
begin
sgInvoice.Canvas.Brush.Color := clAppWorkSpace;
sgInvoice.Canvas.FillRect(Rect);
sginvoice.Canvas.Font.Color := clWhite;
sgInvoice.Canvas.TextOut(Rect.Left + 2 , Rect.Top + 2, sgInvoice.Cells[ACol, ARow]);
end;
else
begin
sgInvoice.Canvas.Brush.Color := clWindow;
sgInvoice.Canvas.FillRect(Rect);
sgInvoice.Canvas.Pen.Color := clBlack;
sgInvoice.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, sgInvoice.Cells[ACol, ARow]);
end;
end; {case}
//create a word break if a line exceeds column width
S:= sgInvoice.Cells[ACol, ARow ];
If Length(S) > 0 Then
begin
drawrect := rect;
DrawText(sgInvoice.canvas.handle,
Pchar(S), Length(S), drawrect,
dt_calcrect or dt_wordbreak); // or dt_left );
If (drawrect.bottom - drawrect.top) >
(sgInvoice.RowHeights[ARow]) then
sgInvoice.RowHeights[ARow] := (drawrect.bottom - drawrect.top)
// changing the row height fires the event again
else
begin
drawrect.Right := rect.right;
drawrect.Left := rect.Left + 2;
drawrect.Top := rect.Top + 2;
sgInvoice.canvas.fillrect( drawrect );
DrawText(sgInvoice.canvas.handle,
Pchar(S), Length(S), drawrect,
dt_wordbreak); // or dt_left);
end;
end;
end;
------------------------------------
There's no place like 127.0.0.1
------------------------------------