紧急情况,高手们请看看。(100分)

  • 主题发起人 主题发起人 tiger_520
  • 开始时间 开始时间
T

tiger_520

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:(在stringgrid的drawcell事件中)
k:=stringgrid1.colcount-1;
if (Acol=k) then
begin
if (stringgrid1.cells[k,Arow]='1') and (stringgrid1.cells[k-1,Arow]='0')
and(stringgrid1.cells[k-2,Arow]='1')and(stringgrid1.cells[k-3,Arow]='0') then
begin
stringgrid1.canvas.brush.color:=clred;
stringgrid1.fillrect(stringgrid1.cellrect[k,Arow]);
stringgrid1.canvas.textout(rect.top,rect.left,stringgrid1.cells[k,Arow]);
stringgrid1.canvas.brush.color:=clred;
stringgrid1.fillrect(stringgrid1.cellrect[k-1,Arow]);
stringgrid1.canvas.textout(rect.top,rect.left,stringgrid1.cells[k-1,Arow]);
stringgrid1.canvas.brush.color:=clred;
stringgrid1.fillrect(stringgrid1.cellrect[k-2,Arow]);
stringgrid1.canvas.textout(rect.top,rect.left,stringgrid1.cells[k-2,Arow]);
stringgrid1.canvas.brush.color:=clred;
stringgrid1.fillrect(stringgrid1.cellrect[k-3,Arow]);
stringgrid1.canvas.textout(rect.top,rect.left,stringgrid1.cells[k-3,Arow]);
end;
end;
本来要达到的要求是将stringgrid一列中的连续cells中的内容为1、0、1、0的CELLS变成红色
可是我却只能将第一个CELLS变成红色。该如何编写这段代码,能够将1、0、1、0都变成红色啊~~谢谢
 
把这个
if (Acol=k) then
改成
if ((Acol<=k) and (Acol>=k-3)) then
////////////////////////
 
刚才没看你下面的代码,改成下面的应该可以

k:=stringgrid1.colcount-1;
if ((Acol<=k) and (Acol>=k-3)) then
begin
if (stringgrid1.cells[k,Arow]='1') and (stringgrid1.cells[k-1,Arow]='0')
and(stringgrid1.cells[k-2,Arow]='1')and(stringgrid1.cells[k-3,Arow]='0') then
begin
stringgrid1.canvas.brush.color:=clred;
stringgrid1.fillrect(Rect);
////
stringgrid1.canvas.textout(rect.Left+2,rect.Top+2,stringgrid1.cells[ACol,Arow]);
//// /// /////
end;
end;
 
你原先代码问题比较多,我没看清楚!
 
接受答案了.
 
if 本列=1 then
if 检查后三列是否为 0,1,0, then
如果符合,显红色
else
如果不符
if 检查前两列是否为1,0 then
如果符合
if 检查后一列是否为0 then
如果符合,显红色;


判断0也是类似,这是最简单的方法,
还有一种方法,取出以本列为中心的7列值,形成一个二进制数比如:0110010,然后分别与
1111000,0111100,0011110,0001111进行与运算,如果相应等于1010000,0101000,0010100,0001010
那就是符合结果的,只要有一个比较符合结果就是可以的
 
后退
顶部