var CurCol,CurRow:integer;procedure TForm1.StringGrid1Click(Sender: TObject); begin CurCol:=StringGrid1.Selection.left; CurRow:=StringGrid1.Selection.Top; StringGrid1.Refresh; end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if ACol*ARow=0 then exit; if ((ACol<CurCol) and (ARow=CurRow)) or ((ARow<CurRow) and (ACol=CurCol)) then ImageList1.Draw(StringGrid1.Canvas,Rect.Left,Rect.Top,2); end;
上面的代码是在选中的行、列上面画一个图标。 下面的代码能够变色。 var CurCol,CurRow:integer; procedure TForm1.Button1Click(Sender: TObject); var i,j:integer; begin StringGrid1.RowCount:=StrToInt(Edit1.Text); StringGrid1.ColCount:=StrToINt(Edit2.Text); for i:=0 to StrToInt(Edit1.Text) do for j:=0 to StrToInt(Edit2.Text) do StringGrid1.Cells[i,j]:=IntToStr(i*j); end;procedure TForm1.StringGrid1Click(Sender: TObject); begin CurCol:=StringGrid1.Selection.left; CurRow:=StringGrid1.Selection.Top; StringGrid1.Refresh; end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if CurCol*CurRow*ACol*ARow=0 then exit; if ((ACol<=CurCol) and (ARow=CurRow)) or ((ARow<CurRow) and (ACol=CurCol)) then begin StringGrid1.Canvas.Brush.Color:=clBlue; end else begin StringGrid1.Canvas.Brush.Color:=clWindow; end; StringGrid1.Canvas.FillRect(Rect); StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[ARow,ACol]); end;
CurCol,CurRow:integer;procedure TForm1.StringGrid1Click(Sender: TObject);
begin
CurCol:=StringGrid1.Selection.left;
CurRow:=StringGrid1.Selection.Top;
StringGrid1.Refresh;
end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if ACol*ARow=0 then
exit;
if ((ACol<CurCol) and (ARow=CurRow)) or ((ARow<CurRow) and (ACol=CurCol)) then
ImageList1.Draw(StringGrid1.Canvas,Rect.Left,Rect.Top,2);
end;
下面的代码能够变色。
var
CurCol,CurRow:integer;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
begin
StringGrid1.RowCount:=StrToInt(Edit1.Text);
StringGrid1.ColCount:=StrToINt(Edit2.Text);
for i:=0 to StrToInt(Edit1.Text) do
for j:=0 to StrToInt(Edit2.Text) do
StringGrid1.Cells[i,j]:=IntToStr(i*j);
end;procedure TForm1.StringGrid1Click(Sender: TObject);
begin
CurCol:=StringGrid1.Selection.left;
CurRow:=StringGrid1.Selection.Top;
StringGrid1.Refresh;
end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if CurCol*CurRow*ACol*ARow=0 then
exit; if ((ACol<=CurCol) and (ARow=CurRow)) or ((ARow<CurRow) and (ACol=CurCol)) then
begin
StringGrid1.Canvas.Brush.Color:=clBlue;
end else
begin
StringGrid1.Canvas.Brush.Color:=clWindow;
end;
StringGrid1.Canvas.FillRect(Rect);
StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[ARow,ACol]);
end;
楼上这句什么意思呀/
我把HELP的代码COPY到程序中,没什么效果呀!
这句是把ImageList1中的index为2的图画到StringGrid1的画布上,从位置Rect.Left,Rect.top开始画。
CurRow:=StringGrid1.Selection.Top;是怎么理解的呀 ,
当前行 在所选中单元的最高
当前列 在所选中单元的最左?