Mario Lopes Posted March 30, 2012 Report Share Posted March 30, 2012 Boa noiteComo posso saber a cor de uma célula numa stringgrid onde cliquei com o rato? A cor da fonte ou a cor da célula.Obrigado Quote Link to comment Share on other sites More sharing options...
0 Jhonas Posted March 30, 2012 Report Share Posted March 30, 2012 vejahttp://www.activedelphi.com.br/forum/viewt...ight=stringgridabraço Quote Link to comment Share on other sites More sharing options...
0 Mario Lopes Posted March 31, 2012 Author Report Share Posted March 31, 2012 Não é fácil amigoVeja 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. Quote Link to comment Share on other sites More sharing options...
0 Jhonas Posted March 31, 2012 Report Share Posted March 31, 2012 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 Quote Link to comment Share on other sites More sharing options...
0 Mario Lopes Posted April 1, 2012 Author Report Share Posted April 1, 2012 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çoValeu amigo, abraço Quote Link to comment Share on other sites More sharing options...
Question
Mario Lopes
Boa noite
Como posso saber a cor de uma célula numa stringgrid onde cliquei com o rato? A cor da fonte ou a cor da célula.
Obrigado
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.