我想问下,DrawCell 事件是什么意思,好像是什么自绘制, 请问这个事件只有 stringgrid 有吗?像我想改变一个stringgrid 已知坐标 的单元格的 字符串 颜色 怎么实现?  还有里面的属性具体怎么用 的  谁有这方面的 资料 给我说下谢谢, 最好 基础点的!

解决方案 »

  1.   

    DGGroid
    ListBox
    ComBoBox都有类似的自绘事件但我对StringGrid也不熟悉--->
    感觉应该是用ACol, ARow: Integer来判断坐标所在的单元格
    通过Rect设置画布范围
    Cnvs := (Control as Tstringgrid).Canvas;
        Cnvs.Brush.Color := clSkyBlue;
        Cnvs.Pen.Color := clNavy;大致应该是用到这些代码吧
      

  2.   


    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      with Sender as TStringGrid do  begin
        if (ARow mod 2 =0) then begin  //当行为偶数色为
          Canvas.Brush.Color := clBtnFace;//画布颜色
          Canvas.font.Color:=clblack;//字体色
        end
        else
        begin
          Canvas.Brush.Color := clgreen;
          Canvas.font.Color := clWhite;
        end;
          Canvas.FillRect(Rect);
          canvas.textout(rect.Left,rect.Top,cells[Acol,ARow]);
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
    StringGrid1.Cells[0,0] := '姓名';
    StringGrid1.Cells[1,0] := '学号';
    StringGrid1.Cells[2,0] := '班级';
    StringGrid1.Cells[3,0] := '课程';
    StringGrid1.Cells[4,0] := '分数';
    StringGrid1.Cells[0,1] := '张三';
    StringGrid1.Cells[1,1] := '001';
    StringGrid1.Cells[2,1] := '高三一班';
    StringGrid1.Cells[3,1] := '语文';
    StringGrid1.Cells[4,1] := '9';
    StringGrid1.Cells[0,2] := '李四';
    StringGrid1.Cells[1,2] := '002';
    StringGrid1.Cells[2,2] := '高三二班';
    StringGrid1.Cells[3,2] := '数学';
    StringGrid1.Cells[4,2] := '99';
    StringGrid1.Cells[0,3] := '王五';
    StringGrid1.Cells[1,3] := '001';
    StringGrid1.Cells[2,3] := '高三一班';
    StringGrid1.Cells[3,3] := '数学';
    StringGrid1.Cells[4,3] := '19';
    end;网上很多的呀