源码实例下载:https://download.csdn.net/download/lzksword/87904787
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "AdvGrid"
#pragma link "AdvObj"
#pragma link "BaseGrid"
#pragma resource "*.dfm"
TForm1 *Form1;
bool XSyn =false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
AdvStringGrid1->FixedCols=0;
AdvStringGrid1->FixedRows=0;
for(int i=0;i
{
AdvStringGrid1->ColWidths[i]=22;
for(int j=0;j
{
AdvStringGrid1->Cells[i][j]=i;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AdvStringGrid1DrawCell(TObject *Sender, int ACol, int ARow,
TRect &Rect, TGridDrawState State)
{
String XStr = AdvStringGrid1->Cells[ACol][ARow] ;
int x=Rect.left + (Rect.Width() - AdvStringGrid1->Canvas->TextWidth(XStr))/2; // -- 水平居中 // -- 垂直居上
int y=Rect.top + (Rect.Height() - AdvStringGrid1->Canvas->TextHeight(XStr))/2;//
AdvStringGrid1->Canvas->Pen->Color =clRed;
AdvStringGrid1->Canvas->Brush->Color =clRed;
AdvStringGrid1->Canvas->Ellipse(Rect);
//
AdvStringGrid1->Canvas->Font->Color = clWhite; //字体颜色
AdvStringGrid1->Canvas->TextOutW(x,y,XStr);
if(XSyn) //是否显示画线
{
AdvStringGrid1->Canvas->Pen->Color=clBlue; //画线颜色
AdvStringGrid1->Canvas->Pen->Style=psSolid; //画线样式
AdvStringGrid1->Canvas->Pen->Width=2; //画笔粗细
//AdvStringGrid1->Canvas->MoveTo(AdvStringGrid1->CellRect(1,1).Left/2,AdvStringGrid1->CellRect(1,1).Top/2);
//AdvStringGrid1->Canvas->LineTo(AdvStringGrid1->CellRect(2,2).Right/2,AdvStringGrid1->CellRect(2,2).Bottom/2);
//计算描线的坐标点
x=AdvStringGrid1->CellRect(0,0).left+AdvStringGrid1->CellRect(0,0).Width()/2;
y=AdvStringGrid1->CellRect(0,0).top+AdvStringGrid1->CellRect(0,0).Height()/2;
AdvStringGrid1->Canvas->MoveTo(x,y);
x=AdvStringGrid1->CellRect(7,1).left+AdvStringGrid1->CellRect(7,1).Width()/2;
y=AdvStringGrid1->CellRect(7,1).top+AdvStringGrid1->CellRect(7,1).Height()/2;
AdvStringGrid1->Canvas->LineTo(x,y);
x=AdvStringGrid1->CellRect(3,2).left+AdvStringGrid1->CellRect(3,2).Width()/2;
y=AdvStringGrid1->CellRect(3,2).top+AdvStringGrid1->CellRect(3,2).Height()/2;
AdvStringGrid1->Canvas->LineTo(x,y);
x=AdvStringGrid1->CellRect(4,3).left+AdvStringGrid1->CellRect(4,3).Width()/2;
y=AdvStringGrid1->CellRect(4,3).top+AdvStringGrid1->CellRect(4,3).Height()/2;
AdvStringGrid1->Canvas->LineTo(x,y);
x=AdvStringGrid1->CellRect(0,4).left+AdvStringGrid1->CellRect(0,4).Width()/2;
y=AdvStringGrid1->CellRect(0,4).top+AdvStringGrid1->CellRect(0,4).Height()/2;
AdvStringGrid1->Canvas->LineTo(x,y);
x=AdvStringGrid1->CellRect(9,5).left+AdvStringGrid1->CellRect(9,5).Width()/2;
y=AdvStringGrid1->CellRect(9,5).top+AdvStringGrid1->CellRect(9,5).Height()/2;
AdvStringGrid1->Canvas->LineTo(x,y);
x=AdvStringGrid1->CellRect(8,6).left+AdvStringGrid1->CellRect(8,6).Width()/2;
y=AdvStringGrid1->CellRect(8,6).top+AdvStringGrid1->CellRect(8,6).Height()/2;
AdvStringGrid1->Canvas->LineTo(x,y);
x=AdvStringGrid1->CellRect(1,7).left+AdvStringGrid1->CellRect(1,7).Width()/2;
y=AdvStringGrid1->CellRect(1,7).top+AdvStringGrid1->CellRect(1,7).Height()/2;
AdvStringGrid1->Canvas->LineTo(x,y);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
XSyn=true;
AdvStringGrid1->Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
XSyn=false;
AdvStringGrid1->Refresh();
}