定义了全局变量 NowCol NowRow 点击按钮,焦点自动移动,但是遇到换列的时候就不对了。是因为先执行了
StringGrid.Col:=NowCol; 后执行了StringGrid.Row:=NowRow;造成了行列显示焦点混乱。请教有什么办法解决吗?procedure TFrm_Main.Button1Click(Sender: TObject);begin
NowCol:=(Trunc(RzNumericEdit.Value)-1) div 10 ;
NowRow:=(Trunc(RzNumericEdit.Value)-1) mod 10;
StringGrid.setFocus;
StringGrid.Col:=NowCol;
StringGrid.Row:=NowRow;
StringGrid.Cells[NowCol,NowRow]:='K';
end;procedure TFrm_Main.StringGridDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
with StringGrid.Canvas do
begin Brush.Color := clinfobk; //所有格子颜色;
FillRect(Rect);
font.color := clblue;
textout(rect.left, rect.top, RzStringGrid.cells[Acol, ARow]); end;
with StringGrid.Canvas do
begin
if (ACol = Nowcol) and (ARow = Nowrow) then
begin
Brush.Color := clred; //选定的格子颜色;
FillRect(Rect);
font.color := clblack;
textout(Rect.Left + 2, Rect.Top + 2, StringGrid.cells[Nowcol, Nowrow]);
end;
end;
end;
procedure TFrm_Main.StringGridSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if CanSelect then
begin
NowCol := ACol;
NowRow := ARow;
end;end;
StringGrid.Col:=NowCol; 后执行了StringGrid.Row:=NowRow;造成了行列显示焦点混乱。请教有什么办法解决吗?procedure TFrm_Main.Button1Click(Sender: TObject);begin
NowCol:=(Trunc(RzNumericEdit.Value)-1) div 10 ;
NowRow:=(Trunc(RzNumericEdit.Value)-1) mod 10;
StringGrid.setFocus;
StringGrid.Col:=NowCol;
StringGrid.Row:=NowRow;
StringGrid.Cells[NowCol,NowRow]:='K';
end;procedure TFrm_Main.StringGridDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
with StringGrid.Canvas do
begin Brush.Color := clinfobk; //所有格子颜色;
FillRect(Rect);
font.color := clblue;
textout(rect.left, rect.top, RzStringGrid.cells[Acol, ARow]); end;
with StringGrid.Canvas do
begin
if (ACol = Nowcol) and (ARow = Nowrow) then
begin
Brush.Color := clred; //选定的格子颜色;
FillRect(Rect);
font.color := clblack;
textout(Rect.Left + 2, Rect.Top + 2, StringGrid.cells[Nowcol, Nowrow]);
end;
end;
end;
procedure TFrm_Main.StringGridSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if CanSelect then
begin
NowCol := ACol;
NowRow := ARow;
end;end;
解决方案 »
- 求货币数字输入组件
- 请问: 如何在一个exe程序里面,判断令一个exe程序是否在运行??? 多谢!
- 请教:计时除了用ttimer组件外,还有其它方式吗?我听说有一种系统递归式计时,如何实现?或其他方式?
- 简单问题-急等
- 哪有DEPHI6 6月20号发布的纯中文版的D版!!!???
- 我新来,怎么给分
- 怎么将二进制字符串读到流中
- 哪位知道高级程序员哪天开考
- 万分火急,请教访问数据库速度问题!多谢!!!
- 自己完成开发的程序通过何种途径买出去?,使自己开发程序成为商品程序还应注意哪些问题??请发表高见??
- 请问用DELPHI开发一般用什么UML工具
- 请问我写了一个读取进程列表的小程序可是会出错不知道为什么。
procedure TFrm_Main.StringGridSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
if CanSelect then
begin
NowCol := ACol;
NowRow := ARow;
end;
var
i:Integer;
row,col:Integer;
begin
i:=self.StringGrid1.RowCount;
vg_col:=(Trunc(RzNumericEdit1.Value)) div i;
vg_row:=(Trunc(RzNumericEdit1.Value)) mod i;
//StringGrid1.setFocus;
if vg_col+1>self.StringGrid1.ColCount then
begin
MessageBox(application.Handle,'超出表格范围','信息',MB_OK or MB_ICONINFORMATION);
Exit;
end;
//注意这部分
col:=vg_col;
row:=vg_row;
StringGrid1.Col:=col;//在修改这个值时,会再次调用selectcell,所以会出现错误
StringGrid1.Row:=row;
vg_col:=col;
vg_row:=row;
//**********************
StringGrid1.Cells[vg_col,vg_row]:='K';
end;