to 娃娃
tstrings中有一组号码是通过一些公式得到.比如
05 06 28 19
33 24 08 17 29 44
我就临时创建10 个圆.在这些圆上分别写上这些数字.我窗体上已经很满了,又不想把它放到另外的窗口上.因此就想放在DBGRID上,用完刷新一下就可以了.经过一下午试验,还有点问题没解决.我想字体的颜色为白色(现在字体为黑色,底为白色)底色同圆的颜色.不知这样说有没有说清楚? 把下面的代码贴过去就可以试
dc: hdc;
rgn: hrgn;
implementation
const
X_BB1='01 02 07 08 12 13 18 19 23 24 29 30 34 35 40 45 46';
X_BB2='03 04 09 10 14 15 20 25 26 31 36 37 41 42 47 48';
X_BB3='05 06 11 16 17 21 22 27 28 32 33 38 39 43 44 49';
{$R *.dfm}
//返回字符串是否是正确的数字表达
function IsNumber(mStr: string): Boolean; stdcall;
var
I: Real;
E: Integer;
begin
Val(mStr, I, E);
Result := E = 0;
E := Trunc(I);
end;
//在字符前面加增加指定字符
function Add_Space(str,AddStr:string;Size:integer):string;stdcall;
begin
result:=str;
if length(str)>=size then exit;
while length(result)<size do
result:=AddStr+result;
end;
function GetBS(NumStr:String):TColor;//波色
begin
Result:=clBtnFace;
if IsNumber(NumStr) then
NumStr:=Add_Space(NumStr,'0',2);
if AnsiContainsText(X_BB1,NumStr) then
result:=clRed;
if AnsiContainsText(X_BB2,NumStr) then
result:=clBlue;
if AnsiContainsText(X_BB3,NumStr) then
result:=clGreen;
end;
{
memo中的内容
05 06 28 19
33 24 08 17 29 44
}
procedure TForm1.Button2Click(Sender: TObject);
var
i,J: integer;
T,L,R: Integer;
KX: Integer;//空隙
aColor: TColor;
NewPen: TPen;
SavePen: HGDIOBJ;
tmpL: TStrings;
s: string;
begin
L:=20;
T:=50;
R:=34;
KX:=6;
NewPen:=TPen.Create;
tmpL:=TStringList.Create;
DC:=GetDC(dbGrid1.Handle);
for i := 0 to memo1.Lines.Count-1 do
begin
s:=memo1.Lines.Strings;
tmpL.Clear;
tmpL.Text:=StringReplace(s, ' ', #13#10, [rfReplaceAll]);
for j := 0 to tmpL.Count-1 do
begin
aColor:=GetBS(tmpL.Strings[J]);
Ellipse(dc,L+R*J+KX*J,T+KX*I+R*I,L+R*J+KX*J+R,T+KX*I+R*I+R);
rgn:=CreateEllipticRgn(L+R*J+KX*J,T+KX*I+R*I,L+R*J+KX*J+R,T+KX*I+R*I+R);
SelectClipRgn(dc,rgn);
FillRect(dc,dbGrid1.ClientRect,CreateSolidBrush(aColor));
//************************
{
font.Name:='宋体';
Font.Color:=clWhite;
font.Size:=R-20;
}
textout(dc,L+R*J+KX*J+8,T+KX*I+R*I+8,pchar(tmpL.strings[j]),2);
newPen.color:=aColor;
newPen.width:=4;
savePen:= SelectObject(dc,newPen.handle);
selectObject(dc,savePen);
//************************
end;
end;
end;