StringGrid1 加颜色交替的两种颜色,料单编号永远不重复的。料单编号
11110 红
11110 红
33334 绿
33334 绿
33334 绿
15310 红
61020 红
61020 红注意 后面的“红”“绿”是我加上去给个提示告诉你,还是以料单编号为准不知道怎么写代码。
主要是写代码思路,不知道你们明白我的意思啵?
11110 红
11110 红
33334 绿
33334 绿
33334 绿
15310 红
61020 红
61020 红注意 后面的“红”“绿”是我加上去给个提示告诉你,还是以料单编号为准不知道怎么写代码。
主要是写代码思路,不知道你们明白我的意思啵?
解决方案 »
- 发一个在Delphi中使用的memcmp和C中使用的memcmp函数的参数和返回值是完全一样的。
- 关于保存一个Record类型到文件中的问题
- 期待高手: TClientSocket 如何接收记录类型(record)?
- 关于两个文本框文字之间的比较?
- 过年导粪的注意啦!!
- quickreport打印后,关闭出现错误!马上那分!
- 关于stringgrid得问题!
- 求使用odac调用oracle存储过程的方法和实例
- 求结构体转换delphi,调用dll!在线等
- 究竟如何才能真正地利用DELPHI做一些东西呢? 有大侠愿意收徒弟么?
- 关于 IdHTTPServer的通讯问题(分不够再加,帮定有分,呵呵)
- delphi加密函数问题
就是StringGrid表里,有料单编号。要给他们加字体颜色。上面讲得好清楚了。
Rect: TRect; State: TGridDrawState);
begin
with StringGrid1 do
if Cells[ACol,ARow] = '11110' then
begin
Canvas.Font.Color := clred; //字体颜色为红的
Canvas.Brush.color:=clMoneyGreen; //背景为 美元绿色
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]);
end else if ................
..............
end;
啊,有一万条,不同的料单编号。都要做一万if..then吗?
11110 红
11110 红
33334 绿
33334 绿
33334 绿
15310 红
61020 红
61020 红
你在向stringgrid1中加载数据时,增加一个列(不显示),第一行的这列存入1,当下面一条与前一条相同是就将这个列存入1不同存入0,依次类推,这样你的这个列就只有两个值,然后在onDrawCell事件中写关于颜色的处理.
var
iR: integer;
vCStr: String;
begin
setstrgrid(StringGrid1);
for iR:=0 to Memo1.Lines.Count-1 do
begin
StringGrid1.cells[0,iR+1]:= IntToStr(iR);
StringGrid1.cells[1,iR+1] := trim(Memo1.Lines[iR+1]);
vCStr := trim(Memo1.Lines[iR+1]);
if iR=0 then
StringGrid1.cells[2,iR+1] := '1'
else begin
if vCStr = StringGrid1.cells[1,iR] then
StringGrid1.cells[2,iR+1] := StringGrid1.cells[2,iR]
else begin
if StringGrid1.cells[2,iR]='0' then StringGrid1.cells[2,iR+1] := '1'
else StringGrid1.cells[2,iR+1] := '0';
end;
end;
StringGrid1.RowCount := StringGrid1.RowCount + 1;
end;
end;procedure TForm1.setstrgrid(strGrid:TStringGrid);
Var
i,j:integer;
begin
with strGrid do
begin
for i:=fixedrows to rowcount-1 do
for j:=FixedCols to colcount-1 do
cells[j,i]:='';
end;
end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
SetGridColor(ARow,ACol,clRed,clGreen,Rect,StringGrid1);
end;
procedure TForm1.SetGridColor(ARow,ACol: Integer;ColorJ,ColorO: TColor; Rect: TRect;StrGrid: TStringGrid);
var
strValue: String;
begin
with StrGrid do
begin
if (ARow > 0) and (ACol > 0) then
begin
if Cells[2,ARow] = '1' then
Canvas.Brush.Color := ColorO
else if Cells[2,ARow] = '0' then
Canvas.Brush.Color := ColorJ
else Canvas.Brush.Color := clWhite;
Canvas.FillRect(Rect);
end;
//计算显示在矩形框中的左上角位置
strValue := Cells[ACol,ARow];
Canvas.Font := Font;
//在矩形框中写值
Canvas.TextRect(Rect,Rect.Left+5,Rect.Top+(Rect.Bottom-Rect.Top-Canvas.TextHeight(strValue)) div 2,strValue);
end;
end;
兄弟你的写代码好长,幸苦了。我已解决了。方法是if StringGrid1.Cells[2,j]=StringGrid1.Cells[2,j-1] then 是‘1’ else 是'0' 。过会儿散分