Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Pintar una columna de una grilla (https://www.clubdelphi.com/foros/showthread.php?t=34627)

zugazua2001 16-08-2006 05:13:36

Pintar una columna de una grilla
 
Hola amigos del foro, tengo la siguiente duda, se puede dentro del campo de una grilla, por ejemplo del tipo A:20 pintar la mitad de los caracteres de un color y la otra mitad de otro?

Muchas gracias por todo.

zugazua2001 16-08-2006 15:51:20

se puede
 
Se puede parte de un color y parte de otro¿?
Gracias

seoane 16-08-2006 16:26:10

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;


La franja horaria es GMT +2. Ahora son las 20:22:53.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi