1. 文字居中 加 選中時(焦點) 虛邊框 如何加顏色
procedure tform1.stringgrid1drawcell(sender: tobject; acol, arow: integer;
rect: trect; state: tgriddrawstate);
var
vtext: pchar;
begin
with tstringgrid(sender) do begin
vtext := pchar(cells[acol, arow]);
canvas.fillrect(rect);
drawtext(canvas.handle, vtext, strlen(vtext), rect,
dt_center or dt_vcenter or dt_singleline); //重繪單元格
if gdfocused in state then begin //同意camel_luo//我來加一條
rect.left := rect.left + 1;
rect.top := rect.top + 1;
rect.right := rect.right - 1;
rect.bottom := rect.bottom - 1;
canvas.drawfocusrect(rect);
end;
end;
end;
2. 當行變色 指在編輯的狀態下 區分當前 顯示當前行與其他行的區別
if goperatestate<>'瀏覽' then
with tstringgrid(sender) do
begin
if (inttostr(old)<>'0') and (old<>cur) then
begin
for i:=1 to stringgrid1.colcount-1 do
begin
str:= stringgrid1.cells[i,old];
frect:=stringgrid1.cellrect(i,old); //獲取區域
canvas.brush.color:=clcream; //填充顏色 白色
canvas.fillrect(frect); //區域填充
settextcolor(canvas.handle, clblack); //文字顏色
drawtext(canvas.handle, pchar(str), length(str), frect, 0); //windows.pas 即 win32api 呼叫外部函式 stdcall
end;
end;
if (inttostr(cur)<>'0') and (stringgrid1.row=cur) and (stringgrid1.row<>0) and (old<>stringgrid1.row) then
begin
old:=cur; //新一行 舊一行
for i:=1 to stringgrid1.colcount-1 do
begin
str:= stringgrid1.cells[i,stringgrid1.row];
frect:=stringgrid1.cellrect(i,stringgrid1.row);
canvas.brush.color:=clskyblue;
canvas.fillrect(frect);
settextcolor(canvas.handle, clblack);
drawtext(canvas.handle, pchar(str), length(str), frect, 0);
end;
end;
end;
StringGrid控制項
stringgrid控制項 元件名稱 stringgrid 固定行及固定列 stringgrid.fixedcols 固定行之數 stringgrid.fixedrows 固定列之數 stringgrid.fixedcolor 固定行列之顏色 stringgrid.color 資料區之顏色 資料行列...
VBS控制項 StringGrid
在屬性的options裡面有乙個gocolsizing的,改為true即可讓使用者可調寬度。stringgrid.colcount 列數 stringgrid.cells a,b a 列數 b 行數 stringgrid.colwidths a 列寬 a 列數 stringgrid.rowcount...
StringGrid系列文章2
在string的灰色單元中寫的字能夠分成兩行 stringgrid控制項如何連線按鈕控制項 mouse在tstringgrid外單擊時,tstringgrid如何得到通知 如何在stringgrid當前行第一列也像dbgrid樣標出箭頭呢 如何在delphi 的stringgrid 控制項的 cel...