一段个性化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;
?? //實現(xiàn) 將 其他控件 浮動在表格框里的效果。
??? 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;
轉(zhuǎn)載于:https://www.cnblogs.com/wmymtx/archive/2011/12/10/2283527.html
總結
以上是生活随笔為你收集整理的一段个性化stringgrid的代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牙齿矫正大概要多少钱啊?
- 下一篇: 2022世界杯分组名单