欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

一段个性化stringgrid的代码

发布时间:2023/12/1 编程问答 49 豆豆
生活随笔 收集整理的这篇文章主要介绍了 一段个性化stringgrid的代码 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

需要注意的是 该段程序使用了 canvas。

procedure TW_CkbTaiZhang.KhLstDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
   if ARow=khlst.Row then
   with khlst.Canvas do //画 cell 的边框
    begin
      Pen.Color := $00ff0000; //定义画笔颜色(蓝色)
      MoveTo(Rect.Left, Rect.Bottom); //画笔定位
      LineTo(Rect.Right, Rect.Bottom); //画蓝色的横线
      Brush.Color :=TColor(RGB(10,100,100));
      fillrect(rect);
      textout(rect.left+4,rect.top+4,khlst.cells[ACol,ARow]);   //一定要使用textout输出文字才能将效果输出。
    end;

   //实现 将 其他控件 浮动在表格框里的效果。
    if (gdFocused in state) then
    begin
      if KhLst.ItemCheck[4, ARow] then
      begin
        if ACol in [5] then
        begin
          cmbYearMonth.Left := Rect.Left + KhLst.Left;
          cmbYearMonth.Top := rect.Top +KhLst.Top;
          cmbYearMonth.Width :=rect.Right-rect.Left;
          cmbYearMonth.Height :=rect.Bottom - rect.Top;
          cmbYearMonth.Text :=khlst.Cells[ACol,ARow];
          cmbYearMonth.Visible := true;
          cmbYearMonth.SetFocus;
        end else cmbyearmonth.Visible := false;
        if ACol in [6] then
        begin
          cmbbxh.Left := Rect.Left + KhLst.Left;
          cmbbxh.Top := rect.Top +KhLst.Top;
          cmbbxh.Width :=rect.Right-rect.Left;
          cmbbxh.Height :=rect.Bottom - rect.Top;
          cmbbxh.Text :=khlst.Cells[ACol,ARow];
          cmbbxh.Visible := true;
          cmbbxh.SetFocus;
        end else cmbbxh.Visible :=false;
        if ACol in [7] then
        begin
          cmbbrl.Left := Rect.Left + KhLst.Left;
          cmbbrl.Top := rect.Top +KhLst.Top;
          cmbbrl.Width :=rect.Right-rect.Left;
          cmbbrl.Height :=rect.Bottom - rect.Top;
          cmbbrl.Text :=khlst.Cells[ACol,ARow];
          cmbbrl.Visible := true;
          cmbbrl.SetFocus;
        end else cmbbrl.Visible :=false;
        if aCol in [8] then
        begin
          cmbmc.Left := Rect.Left + KhLst.Left;
          cmbmc.Top := rect.Top +KhLst.Top;
          cmbmc.Width :=rect.Right-rect.Left;
          cmbmc.Height :=rect.Bottom - rect.Top;
          cmbmc.Text :=khlst.Cells[aCol,aRow];
          cmbmc.Visible := true;
          cmbmc.SetFocus;
        end else cmbmc.Visible :=false;
        if acol in [9] then
        begin
          cmbbl.Left := Rect.Left + KhLst.Left;
          cmbbl.Top := rect.Top +KhLst.Top;
          cmbbl.Width :=rect.Right-rect.Left;
          cmbbl.Height :=rect.Bottom - rect.Top;
          cmbbl.Text :=khlst.Cells[aCol,aRow];
          cmbbl.Visible := true;
          cmbbl.SetFocus;
        end else cmbbl.Visible :=false;
      end else
      begin
        cmbYearMonth.Visible :=false;
        cmbbxh.visible :=false;
        cmbmc.Visible :=false;
        cmbbrl.Visible :=false;
        cmbbl.Visible :=false;
      end;
    end;
end;

转载于:https://www.cnblogs.com/wmymtx/archive/2011/12/10/2283527.html

总结

以上是生活随笔为你收集整理的一段个性化stringgrid的代码的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。