stringgrid 使用技巧
2010-11-26 16:29
344 查看
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;
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;
相关文章推荐
- AdvStringGrid使用技巧
- AdvStringGrid使用技巧
- TAdvStringGrid 使用技巧(转载)
- AdvStringGrid使用技巧
- AdvStringGrid 使用技巧(2)(转载)
- TAdvStringGrid控件使用技巧[转]
- Delphi的StringGrid使用技巧代码
- [转]Infragistics NetAdvantage UltraWebGrid使用技巧
- StringGrid使用全书2
- Function.prototype.toString 的使用技巧
- ExtAspNet应用技巧(二十三) - Ext4JSLint之Grid的使用
- [转]Infragistics NetAdvantage UltraWebGrid使用技巧
- js中字符替换函数String.replace()使用技巧
- String的split的使用技巧
- StringGrid使用大全
- advstringgrid 使用
- EOJ 3256 拼音魔法(string+char[]的使用技巧)
- Java中String的一些使用技巧(针对面试s)
- CB控件使用备忘--StringGrid 和 ListView
- DevExpress gridControl的使用技巧总结