joooje
سه شنبه 22 فروردین 1391, 21:12 عصر
سلام به همه دوستان
من میخوام بتونم کاری بکنم که یه سطر از RzStringGrid رو تغییر رنگ بدم (من از کامپوننت RZ استفاده میکنم)
آیا راهی برای این کار وجود داره؟
حتی اگر بتونم تنها یک سلول از هر سطر رو هم تغییر رنگ بدم کارم حل میشه
ممنون میشم راهنمایی کنید
جستجو همرکردم ولی هیچ کمکی نکرد:
تغییر رنگ یک سطر از Stringgride (http://barnamenevis.org/showthread.php?258085-تغییر-رنگ-یک-سطر-از-Stringgride)
روش تغییر رنگ زمینه Cellها در StringGrid (http://barnamenevis.org/showthread.php?83518-روش-تغییر-رنگ-زمینه-Cellها-در-StringGrid)
javad p
چهارشنبه 23 فروردین 1391, 08:28 صبح
سلام
این یه کد برای تغییر رنگ یک سلول
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (ACol=1) and (ARow=2) then with (StringGrid1) do begin
Canvas.Brush.Color:=clRed;
Canvas.FillRect(Rect);
Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,Cells[Col,Row]);
end;
end;
این یه کد دیگه برا تغییر رنگ هنگام کلیک (کلیک آپ):
procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
v,w:integer;
arect:TRect;
begin
stringgrid1.MouseToCell(X,Y,v,w);
arect:=stringgrid1.CellRect(v,w);
stringgrid1.Canvas.Brush.Color:=clred;
stringgrid1.Canvas.FillRect(arect);
end;
اینم کد برای رندم تغییر رنگ دادن:
var FG: array of array of TColor; BG: array of array of TColor;
procedure TForm1.FormCreate(Sender: TObject); var Col, Row: integer; begin // Set the sizes of the arrays SetLength(FG, Grid.ColCount, Grid.ColCount); SetLength(BG, Grid.ColCount, Grid.ColCount); // Initialize with default colors for Col := 0 to Grid.ColCount - 1 do begin for Row := 0 to Grid.RowCount - 1 do begin FG[Col, Row] := clBlack; BG[Col, Row] := clWhite; end; end; end;
procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var S: string; begin S := Grid.Cells[ACol, ARow]; // Fill rectangle with colour Grid.Canvas.Brush.Color := BG[ACol, ARow]; Grid.Canvas.FillRect(Rect); // Next, draw the text in the rectangle Grid.Canvas.Font.Color := FG[ACol, ARow]; Grid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, S); end;
procedure TForm1.GridClick(Sender: TObject); var Col, Row: integer; Colo1, Colo2, Colo3: byte; begin Col := Grid.Col; Row := Grid.Row; // Calculate contrasting random colours Colo1 := 200 + Random(56); Colo2 := 200 + Random(56); Colo3 := 100 + Random(156); BG[Col, Row] := RGB(Colo1, Colo2, Colo3); FG[Col, Row] := RGB(255 - Colo3, 255 - Colo1, 255 - Colo2); // Set the text to be displayed Grid.Cells[Col, Row] := 'clicked'; end;
موفق باشی
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.