如第0列要居中 即 行号 列
第0行要居中 即 字段名 行第1、2列内容要左对齐第3列内容要右对齐初始化
procedure TForm1.FormCreate(Sender: TObject);
var i,j : integer;
begin Stringgrid1.RowCount:=4;
stringgrid1.colcount:=4;
//行号列
stringgrid1.Cells[0,0]:='行号';
for i:=1 to StringGrid1.RowCount-1 do
stringgrid1.Cells[0,i]:=inttostr(i); //字段名行
for i:=1 to StringGrid1.ColCount-1 do
stringgrid1.Cells[i,0]:='字段' + inttostr(i); //内容
for i:=1 to StringGrid1.RowCount-1 do
for j:=1 to StringGrid1.ColCount-1 do
StringGrid1.Cells[j,i]:=inttostr(i*j+100);end;
第0行要居中 即 字段名 行第1、2列内容要左对齐第3列内容要右对齐初始化
procedure TForm1.FormCreate(Sender: TObject);
var i,j : integer;
begin Stringgrid1.RowCount:=4;
stringgrid1.colcount:=4;
//行号列
stringgrid1.Cells[0,0]:='行号';
for i:=1 to StringGrid1.RowCount-1 do
stringgrid1.Cells[0,i]:=inttostr(i); //字段名行
for i:=1 to StringGrid1.ColCount-1 do
stringgrid1.Cells[i,0]:='字段' + inttostr(i); //内容
for i:=1 to StringGrid1.RowCount-1 do
for j:=1 to StringGrid1.ColCount-1 do
StringGrid1.Cells[j,i]:=inttostr(i*j+100);end;
解决方案 »
- 只找到iewords.pas文件,没有找到iewords.dcu文件,怎么解决
- 请长沙的朋友帮忙回答一个简单的问题,或者是熟悉长沙的人都可以. 50+100分相送.
- 〓〓〓简单问题,如何在主窗体显示后执行一段代码?
- 如何解压gzip格式数据?
- 为何从vcl控件转换成ActiveX控件时错处?
- 请各位高手都往这里看,快来看啊!!!!!!!!!!!!!!!!
- 弱智问题
- MYSQL数据库是否支持中文字段名?
- 来者有分。学李维的《ADO/…》第九章时,出现“必须加载一个dll”,渴望!渴望解答!!
- 各位有没有delphi的GIF图片显示控件和窗体移动控件(一定给分)
- 数据库的一个表导出到Excel,如何将这段代码转换成Delphi代码
- 在delphi中如何打开word文档?请教各位高手!!!
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var CellStr: String;
Mode: Integer;
begin
if ARow=0 then
Mode := DT_CENTER //調整左右
else
Mode := DT_RIGHT;
Rect.Top := Rect.Top+3; //調整上下
CellStr := StringGrid1.Cells[ACol,ARow];
StringGrid1.Canvas.FillRect(Rect);
DrawText(StringGrid1.Canvas.Handle,PChar(CellStr),Length(CellStr),Rect,Mode);
end;
var
CX, CY:Integer;
Str:string;
begin
Str := StringGridInfo.cells[acol, arow];
CX := (Rect.Right - Rect.Left - Self.StringGridInfo.Canvas.TextWidth(Str)) div 2;
CY := (Rect.Bottom - Rect.Top - Self.StringGridInfo.Canvas.TextHeight(Str)) div 2;
StringGridInfo.Canvas.TextOut(rect.left + CX, rect.top + CY, Str);
end;