为什么改变窗口大小会使paintbox组件重新显示

没事人 2014-09-27 08:35:20
unit Unitw;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Timer1: TTimer;
PaintBox1: TPaintBox;
L3: TLabel;
procedure PaintBox1Paint(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
x,y,x1,y1,x2,y2:integer;
const
pi=3.1415;

implementation

{$R *.dfm}

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
//l3.Caption:=inttostr(x);
//while 1<2 do
begin
with paintbox1.Canvas do
begin
font.Size:=20;

Textout(trunc(paintbox1.Width/2)-10,trunc(paintbox1.Height/2)-140,'12');
textout(trunc(paintbox1.Width/2)-5,trunc(paintbox1.Height/2)+110,'6');
textout(trunc(paintbox1.Width/2)+160,trunc(paintbox1.Height/2)-15,'3');
textout(trunc(paintbox1.Width/2)-170,trunc(paintbox1.Height/2)-15,'9');//绘制表盘数字
pen.Width:=1;
pen.Color:=clred;
moveto(trunc(paintbox1.Width/2),trunc(paintbox1.Height/2));
lineto(trunc(paintbox1.Width/2+x/1.3),trunc(paintbox1.Height/2-y/1.3));//绘制秒针
pen.Width:=2;
moveto(trunc(paintbox1.Width/2),trunc(paintbox1.Height/2));
lineto(trunc(paintbox1.Width/2-x/4),trunc(paintbox1.Height/2+y/4));
pen.Color:=clgreen;
moveto(trunc(paintbox1.Width/2),trunc(paintbox1.Height/2));
lineto(trunc(paintbox1.Width/2)+trunc(x1/1.5),trunc(paintbox1.Height/2)-trunc(y1/1.5));绘制分针
pen.Width:=4;
pen.Color:=clblack;
moveto(trunc(paintbox1.Width/2),trunc(paintbox1.Height/2));
lineto(trunc(paintbox1.Height/2)-trunc(y2/2.1),trunc(paintbox1.Height/2)-trunc(y2/2.1));//绘制时针
end;
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
len,hh,mm,ss:real;
//i:integer;
j,h:string;
t:tdatetime;
begin
len:=paintbox1.Width/2;
{label1.Caption:=timetostr(time);书上的代码不能运行
label2.Caption:=timetostr(time);
j:=timetostr(time);
while (j[i]<> '\0')do
begin i:=i+1;end;
if copy(timetostr(time),3,1)=':' then
begin
ss:=strtofloat(copy(timetostr(time),7,2));
mm:=strtofloat(copy(timetostr(time),4,2))+ss/60;
hh:=strtofloat(copy(timetostr(time),1,1))+mm/60;
end else
begin
ss:=strtofloat(copy(timetostr(time),6,2));
mm:=strtofloat(copy(timetostr(time),3,2))+ss/60;
hh:=strtofloat(copy(timetostr(time),1,1))+mm/60;
end;}
t:=time;//我自己写的代码,将系统时间转成字符串
j:=timetostr(t);
j:=copy(j,5,13);
j:=copy(j,0,13);
hh:=strtofloat(copy(j,0,3));//获取时
j:=copy(j,5,13);
h:=j;
j:=copy(j,0,2);
mm:=strtofloat(copy(j,0,2));//获取分
h:=copy(h,4,13);
ss:=strtofloat(h);//获取秒
hh:=pi/2-hh/12*2*pi;
mm:=pi/2-mm/60*2*pi;
ss:=pi/2-ss/60*2*pi;//计算三针角度
x:=trunc(len*cos(ss));
y:=trunc(len*sin(ss));
x1:=trunc(len*cos(mm));
y1:=trunc(len*sin(mm));
x2:=trunc(len*cos(hh));
y2:=trunc(len*sin(hh));//计算三针坐标
paintbox1.InitiateAction;
paintbox1.Update;
end;

end.
...全文
753 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
没事人 2014-09-29
  • 打赏
  • 举报
回复
怎么没人理我
没事人 2014-09-27
  • 打赏
  • 举报
回复

这是组件图片
可以运行但是运行后所有指针不动,只有改变窗口大小时指针才会动

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧