
16.05.2008, 14:03
|
Активный
|
|
Регистрация: 25.04.2008
Сообщения: 383
Репутация: 33
|
|
Код:
procedure TForm1.Button1Click(Sender: TObject);
var Days, I, C, R : Integer;
begin
if (DBEdit1.Field = nil) or (DBEdit2.Field = nil) then
Exit;
//количество дней между двумя датами
Days := DaysBetween(DBEdit2.Field.AsDateTime, DBEdit1.Field.AsDateTime);
for C := 0 to SG2.ColCount-1 do
for R := 0 to SG2.RowCount-1 do
SG2.Objects[C, R] := TObject(0);
R := 0; //строка, с которой начинается закраска
C := 0; //колонка, с которой начинается зкраска
for I := 1 to Days do begin
SG2.Objects[C, R] := TObject(1);
Inc(C);
if I mod SG2.ColCount = 0 then begin
Inc(R); C := 0;
end;
end;
SG2.Invalidate;
end;
Код:
procedure TForm1.SG2DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var D : string;
begin
if Integer(SG2.Objects[ACol, ARow]) = 1 then
SG2.Canvas.Brush.Color := clBtnFace
else
SG2.Canvas.Brush.Color := clWhite;
SG2.Canvas.FillRect(Rect);
if (ACol = 0) and (ARow = 0) then begin
if Integer(SG2.Objects[0, 0]) = 1 then begin
DateTimeToString(D, 'mmmm', DBEdit1.Field.AsDateTime);
InflateRect(Rect, -2, -2);
DrawText(SG2.Canvas.Handle, pchar(D), -1, Rect, DT_CENTER);
end;
end;
end;
Только DrawGrid надо заменить на StringGrid, в объектах ячеек которой можно хранить дополнительную информацию. В DrawGrid этого нет.
Свойство StringGrid DefaultDrawing надо установить в False, и создать обработчик OnDrawCell (в примере SG2DrawCell).
|