Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Como saber? Cor de uma célula stringgrid?


Mario Lopes

Question

4 answers to this question

Recommended Posts

  • 0

Não é fácil amigo

Veja a minha situação:

function GetCorCell(calendarGrid: TStringGrid; Coluna,
Linha: Integer): TColor; 
var 
R : TRect; 
Cor : TColor; 
begin 
R := calendargrid.CellRect(Coluna, Linha); 
Result := calendargrid.Canvas.Pixels[R.Left + 2, R.Top + 2];
showmessage(colortostring(result));
end;
Agora no evento selectcell chamo
getcorcell(calendargrid,acol,arow);

A minha grid chama-se calendargrid mas obtenho sempre o mesmo resultado clwhite e uma das células onde clico está com cor vermelha.

Link to comment
Share on other sites

  • 0

amigo, tá facil...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function GetCorCell(Grid: TStringGrid; Coluna,
Linha: Integer): TColor; 
var 
   R : TRect;
   Cor : TColor;
begin
   R := Grid.CellRect(Coluna, Linha);
   Result := Grid.Canvas.Pixels[R.Left + 2, R.Top + 2];
   showmessage(colortostring(result));
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
    GetCorCell(StringGrid1,ACol, ARow);
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
   // colorir uma celula
   if gdSelected in State then
      StringGrid1.Canvas.Brush.Color:= clGreen; //Aqui você coloca a cor de desejar.

   StringGrid1.Canvas.FillRect(Rect); // redesenha a celula
   StringGrid1.Canvas.TextOut(Rect.Left+3,Rect.Top+2,StringGrid1.Cells[acol,arow]);

end;

end.

Nesse exemplo, voce clica numa celula para colorir ... se clicar novamente em cima dela, voce tera como resultado da função a cor atual da celula

abraço

Link to comment
Share on other sites

  • 0
amigo, tá facil...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function GetCorCell(Grid: TStringGrid; Coluna,
Linha: Integer): TColor; 
var 
   R : TRect;
   Cor : TColor;
begin
   R := Grid.CellRect(Coluna, Linha);
   Result := Grid.Canvas.Pixels[R.Left + 2, R.Top + 2];
   showmessage(colortostring(result));
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
    GetCorCell(StringGrid1,ACol, ARow);
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
   // colorir uma celula
   if gdSelected in State then
      StringGrid1.Canvas.Brush.Color:= clGreen; //Aqui você coloca a cor de desejar.

   StringGrid1.Canvas.FillRect(Rect); // redesenha a celula
   StringGrid1.Canvas.TextOut(Rect.Left+3,Rect.Top+2,StringGrid1.Cells[acol,arow]);

end;

end.

Nesse exemplo, voce clica numa celula para colorir ... se clicar novamente em cima dela, voce tera como resultado da função a cor atual da celula

abraço

Valeu amigo, abraço

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...