olbeup
01-04-2015, 13:50:34
Hola Compañer@s,
A la hora de dibujar un cuadrado en una o varias celdas de un StingGrid no hay ningún problemas.
El problema está cuando selecciona la celda que tiene dibujado mas de una celda y sólo me dibuja la primera, no veo la luz al final del tunel.
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
objSG: TGridCell;
SndSG: TStringGrid;
RectDraw, RectText: TRect;
begin
SndSG := (Sender as TStringGrid);
RectDraw := Rect;
InflateRect(RectDraw, -1, -1);
RectText := RectDraw;
InflateRect(RectText, -1, -1);
objSG := (SndSG.Objects[ACol, ARow] as TGridCell);
if (not Assigned(objSG)) then
Exit;
case objSG.Alignment of
taLeftJustify:
Inc(RectText.Left, 2);
taRightJustify:
Dec(RectText.Right, 2);
end;
with SndSG do
begin
if (ACol = objSG.CoordCell.Col) and (ARow = objSG.CoordCell.Row) and (objSG.CoordCell.ColUnion <= 0) then
Exit;
if (ACol = objSG.CoordCell.Col) and (ARow = objSG.CoordCell.Row) and (objSG.CoordCell.ColUnion > 1) then
begin
RectDraw.Right := (RectDraw.Right + objSG.CoordCell.ColUnion -1) + (objSG.CoordCell.DefaultColWidth * (objSG.CoordCell.ColUnion -1));
RectText.Right := RectDraw.Right;
end;
if (gdSelected in State) then
Canvas.RoundRect(RectDraw.Left, RectDraw.Top, RectDraw.Right, RectDraw.Bottom, 3, 3) <--- AQUÍ ES CUANDO DIBUJA SOLO UNA CUANDO TIENE QUE DIBUJAR MAS DE UNA
else
Canvas.Rectangle(RectDraw); <--- AQUÍ LO HACE BIEN
DrawText(Canvas.Handle, PChar(objSG.TextCell), StrLen(PChar(objSG.TextCell)), RectText, objSG.DrawAlign OR DT_VCENTER OR DT_SINGLELINE);
end;
end;
Un saludo.
A la hora de dibujar un cuadrado en una o varias celdas de un StingGrid no hay ningún problemas.
El problema está cuando selecciona la celda que tiene dibujado mas de una celda y sólo me dibuja la primera, no veo la luz al final del tunel.
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
objSG: TGridCell;
SndSG: TStringGrid;
RectDraw, RectText: TRect;
begin
SndSG := (Sender as TStringGrid);
RectDraw := Rect;
InflateRect(RectDraw, -1, -1);
RectText := RectDraw;
InflateRect(RectText, -1, -1);
objSG := (SndSG.Objects[ACol, ARow] as TGridCell);
if (not Assigned(objSG)) then
Exit;
case objSG.Alignment of
taLeftJustify:
Inc(RectText.Left, 2);
taRightJustify:
Dec(RectText.Right, 2);
end;
with SndSG do
begin
if (ACol = objSG.CoordCell.Col) and (ARow = objSG.CoordCell.Row) and (objSG.CoordCell.ColUnion <= 0) then
Exit;
if (ACol = objSG.CoordCell.Col) and (ARow = objSG.CoordCell.Row) and (objSG.CoordCell.ColUnion > 1) then
begin
RectDraw.Right := (RectDraw.Right + objSG.CoordCell.ColUnion -1) + (objSG.CoordCell.DefaultColWidth * (objSG.CoordCell.ColUnion -1));
RectText.Right := RectDraw.Right;
end;
if (gdSelected in State) then
Canvas.RoundRect(RectDraw.Left, RectDraw.Top, RectDraw.Right, RectDraw.Bottom, 3, 3) <--- AQUÍ ES CUANDO DIBUJA SOLO UNA CUANDO TIENE QUE DIBUJAR MAS DE UNA
else
Canvas.Rectangle(RectDraw); <--- AQUÍ LO HACE BIEN
DrawText(Canvas.Handle, PChar(objSG.TextCell), StrLen(PChar(objSG.TextCell)), RectText, objSG.DrawAlign OR DT_VCENTER OR DT_SINGLELINE);
end;
end;
Un saludo.