Ver Mensaje Individual
  #3  
Antiguo 16-08-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Si lo que quieres es pintar en una columna, la mitad de cada celda de un color y la otra mitad de otro, puedes hacer algo así:
Código Delphi [-]
// En el eventon OnDrawCell
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  R: TRect;
begin
  if Sender is TStringGrid then
  begin
    with TStringGrid(Sender), TStringGrid(Sender).Canvas do
    begin
      Canvas.Brush.Style:= bsSolid;
      R:= Rect;
      Canvas.Brush.Color:= clWhite;
      // Pintamos todo el fondo de blanco
      Canvas.FillRect(R);
      // si la columna es la que buscamos, por ejemplo la 3
      if ACol = 3 then
      begin
        R.Right:= (R.Left + R.Right) div 2;
        Canvas.Brush.Color:= clRed;
        // Pintamos la mitad de la celda de rojo
        Canvas.FillRect(R);
      end;
      Canvas.Brush.Style:= bsClear;
      // Escribimos el texto de la celda centradito
      ExtTextOut(Handle,
        (Rect.Left + Rect.Right - TextWidth(Cells[ACol,ARow])) div 2,
        (Rect.Top + Rect.Bottom - TextHeight(Cells[ACol,ARow])) div 2,
        ETO_CLIPPED, @Rect, PChar(Cells[ACol,ARow]),
        Length(Cells[ACol,ARow]),nil);
    end;
  end;
end;

Ahora, si lo que quieres es escribir la mitad de los caracteres de un color y la otra mitad de otro, puedes hacer algo como esto:
Código Delphi [-]
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  x, y: Integer;
  Str1, Str2: String;
begin
  if Sender is TStringGrid then
  begin
    with TStringGrid(Sender), TStringGrid(Sender).Canvas do
    begin
      Canvas.FillRect(Rect);
      Canvas.Brush.Style:= bsClear;
      x:= (Rect.Left + Rect.Right - TextWidth(Cells[ACol,ARow])) div 2;
      y:= (Rect.Top + Rect.Bottom - TextHeight(Cells[ACol,ARow])) div 2;
      Str1:= Copy(Cells[ACol,ARow],1,length(Cells[ACol,ARow]) div 2);
      Str2:= Copy(Cells[ACol,ARow],Length(Str1)+1,length(Cells[ACol,ARow])-Length(Str1));
      Font.Color:= clRed;
      ExtTextOut(Handle,x,y,
        ETO_CLIPPED, @Rect, PChar(Str1),
        Length(Str1),nil);
      x:= x +  TextWidth(Str1);
      Font.Color:= clBlue;
      ExtTextOut(Handle,x,y,
        ETO_CLIPPED, @Rect, PChar(Str2),
        Length(Str1),nil);
    end;
  end;
end;
Responder Con Cita