06-12-2013، 08:13 PM
فایل تغییر رنگ رو ناقص ا\لود کردم.
سورس کد :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
strngrd1: TStringGrid;
btnColor: TButton;
procedure strngrd1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure btnColorClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
selectedCol, selectedRow: Integer;
colorCell: Boolean;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnColorClick(Sender: TObject);
begin
selectedCol:=4;
selectedRow:=4;
colorCell:=True;
strngrd1.Repaint;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
colorCell:=true;
end;
procedure TForm1.strngrd1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if colorCell then
begin
if ((ACol=selectedCol) and (ARow=selectedRow)) then
begin
strngrd1.Canvas.Brush.Color:=RGB(255,0,0); //red brush
strngrd1.Canvas.FillRect(Rect); //paint the backgorund red
//draw the original text
strngrd1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, strngrd1.Cells[ACol, ARow]);
//draw focused rectangle if the current cell is selected by user
if gdFocused in State then
strngrd1.Canvas.DrawFocusRect(Rect);
end;
end;
end;
end.
سورس کد :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
strngrd1: TStringGrid;
btnColor: TButton;
procedure strngrd1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure btnColorClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
selectedCol, selectedRow: Integer;
colorCell: Boolean;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnColorClick(Sender: TObject);
begin
selectedCol:=4;
selectedRow:=4;
colorCell:=True;
strngrd1.Repaint;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
colorCell:=true;
end;
procedure TForm1.strngrd1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if colorCell then
begin
if ((ACol=selectedCol) and (ARow=selectedRow)) then
begin
strngrd1.Canvas.Brush.Color:=RGB(255,0,0); //red brush
strngrd1.Canvas.FillRect(Rect); //paint the backgorund red
//draw the original text
strngrd1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, strngrd1.Cells[ACol, ARow]);
//draw focused rectangle if the current cell is selected by user
if gdFocused in State then
strngrd1.Canvas.DrawFocusRect(Rect);
end;
end;
end;
end.
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg