请教AdvStringGrid1如何设置当前选中行某列的颜色
答案:2 悬赏:80 手机版
解决时间 2021-01-25 03:31
- 提问者网友:低吟詩仙的傷
- 2021-01-25 00:36
请教AdvStringGrid1如何设置当前选中行某列的颜色
最佳答案
- 五星知识达人网友:归鹤鸣
- 2021-01-25 02:05
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, BaseGrid, AdvGrid;
type
TForm1 = class(TForm)
AdvStringGrid1: TAdvStringGrid;
procedure FormShow(Sender: TObject);
procedure AdvStringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure AdvStringGrid1Click(Sender: TObject);
private
{ Private declarations }
FCol, FRow :Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var
LCol, LRow :Integer;
begin
for LCol:=0 to 4 do
AdvStringGrid1.Cells[LCol, 0] := '第' + IntToStr(LCol+1) + '列';
for LRow :=1 to 9 do
begin
AdvStringGrid1.Cells[0, LRow] := '0' + IntToStr(LRow);
AdvStringGrid1.Cells[1, LRow] := '1' + IntToStr(LRow);
AdvStringGrid1.Cells[2, LRow] := '2' + IntToStr(LRow);
AdvStringGrid1.Cells[3, LRow] := '3' + IntToStr(LRow);
AdvStringGrid1.Cells[4, LRow] := '4' + IntToStr(LRow);
end;
end;
procedure TForm1.AdvStringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
AdvStringGrid1.MouseToCell(x, y, FCol, FRow);
end;
procedure TForm1.AdvStringGrid1Click(Sender: TObject);
var
i :Integer;
LColor :TColor;
begin
if (FRow>0) and (FRow<=AdvStringGrid1.RowCount-1) and AdvStringGrid1.RowSelect[FRow] then
begin
AdvStringGrid1.Colors[1, FRow] := clRed;
AdvStringGrid1.Colors[4, FRow] := clRed;
AdvStringGrid1.Repaint;
end;
LColor := AdvStringGrid1.Colors[0,1];
for i:=1 to AdvStringGrid1.RowCount - 1 do
begin
if i <> FRow then
begin
AdvStringGrid1.Colors[1, i] := LColor;
AdvStringGrid1.Colors[4, i] := LColor;
end;
end;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, BaseGrid, AdvGrid;
type
TForm1 = class(TForm)
AdvStringGrid1: TAdvStringGrid;
procedure FormShow(Sender: TObject);
procedure AdvStringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure AdvStringGrid1Click(Sender: TObject);
private
{ Private declarations }
FCol, FRow :Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var
LCol, LRow :Integer;
begin
for LCol:=0 to 4 do
AdvStringGrid1.Cells[LCol, 0] := '第' + IntToStr(LCol+1) + '列';
for LRow :=1 to 9 do
begin
AdvStringGrid1.Cells[0, LRow] := '0' + IntToStr(LRow);
AdvStringGrid1.Cells[1, LRow] := '1' + IntToStr(LRow);
AdvStringGrid1.Cells[2, LRow] := '2' + IntToStr(LRow);
AdvStringGrid1.Cells[3, LRow] := '3' + IntToStr(LRow);
AdvStringGrid1.Cells[4, LRow] := '4' + IntToStr(LRow);
end;
end;
procedure TForm1.AdvStringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
AdvStringGrid1.MouseToCell(x, y, FCol, FRow);
end;
procedure TForm1.AdvStringGrid1Click(Sender: TObject);
var
i :Integer;
LColor :TColor;
begin
if (FRow>0) and (FRow<=AdvStringGrid1.RowCount-1) and AdvStringGrid1.RowSelect[FRow] then
begin
AdvStringGrid1.Colors[1, FRow] := clRed;
AdvStringGrid1.Colors[4, FRow] := clRed;
AdvStringGrid1.Repaint;
end;
LColor := AdvStringGrid1.Colors[0,1];
for i:=1 to AdvStringGrid1.RowCount - 1 do
begin
if i <> FRow then
begin
AdvStringGrid1.Colors[1, i] := LColor;
AdvStringGrid1.Colors[4, i] := LColor;
end;
end;
end;
end.
全部回答
- 1楼网友:纵马山川剑自提
- 2021-01-25 03:16
自画事件里做
advstringgrid1.colors[3,arow]:=clred;
advstringgrid1.colors[5,arow]:=clred;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯