Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- StringGrid1->Cells[1][3]="北京n海淀区n中关村";
- StringGrid1->Cells[2][3]="中华人民共和国西安";
- StringGrid1->Cells[3][3]="上海";
- StringGrid1->Cells[4][3]="深圳";
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
- int ARow, TRect &Rect, TGridDrawState State)
- {
- int align;
- if(ACol<1)return;
- if(ARow<1)return;
- StringGrid1->Canvas->Pen->Color=clWhite;
- StringGrid1->Canvas->Brush->Color=clWhite;
- StringGrid1->Canvas->Brush->Style=bsSolid;
- StringGrid1->Canvas->Rectangle(Rect.Left,Rect.Top,Rect.Right,Rect.Bottom);
- align=2;
- PaintText(Rect.Left+2,Rect.Top+2,ACol,StringGrid1->Cells[ACol][ARow],align);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::PaintText(int x,int y,int col,AnsiString text,int align)
- {
- int ii,yy;
- TStringList *str;
- str=new TStringList();
- str->Text=text;
- yy=1;
- for(ii=0;ii<str->Count;ii++)
- {
- PaintText1(x,y+yy,col,str->Strings[ii],align);
- yy=yy+StringGrid1->Canvas->TextHeight(text);
- }
- delete str;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::PaintText1(int x,int y,int col,AnsiString text,int align)
- {
- int colwd,ww;
- colwd=StringGrid1->ColWidths[col];
- if(align==1)
- {
- ww=StringGrid1->Canvas->TextWidth(text);
- ww=colwd-ww;
- ww/=2;
- if(ww<0)ww=0;
- StringGrid1->Canvas->TextOut(x+ww,y,text);
- }
- else if(align==2)
- {
- ww=StringGrid1->Canvas->TextWidth(text);
- ww=colwd-ww;
- if(ww<0)ww=0;
- StringGrid1->Canvas->TextOut(x+ww,y,text);
- }
- else
- {
- StringGrid1->Canvas->TextOut(x,y,text);
- }
- }
- //---------------------------------------------------------------------------