为什么画了个点后,坐标轴的刻度背景变成了白色?(10分)

  • 主题发起人 主题发起人 锲而不舍
  • 开始时间 开始时间

锲而不舍

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
PaintBox1: TPaintBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

procedure PaintXY;


var
Form1: TForm1;
OriginX,OriginY:integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
PaintBox1.Canvas.Brush.Color:=clBtnFace;
OriginX:=20;
OriginY:=PaintBox1.ClientHeight-20;
end;

procedure PaintXY;
var
k,xt,yt:integer;
begin
Form1.PaintBox1.Canvas.Pen.Color:=clBlack;
with Form1.PaintBox1.Canvas do
begin
MoveTo(OriginX,0); //画坐标系的Y轴
LineTo(OriginX,OriginY);
MoveTo(OriginX,OriginY); //画坐标系的X轴
LineTo(Form1.PaintBox1.ClientWidth,OriginY);
end;
Form1.PaintBox1.Canvas.Pen.Color:=clBlue;
Form1.PaintBox1.Canvas.Font.Color:=clBlue;
k:=Form1.PaintBox1.ClientWidth div 10;
for xt:=1 to 10 do
begin
with Form1.PaintBox1.Canvas do
begin
MoveTo(OriginX+xt * k,OriginY); //画x轴的刻度
LineTo(OriginX+xt * k,OriginY-3);
TextOut(OriginX+xt * k-3,OriginY+3,IntToStr(xt));
end;
end;
k:=Form1.PaintBox1.ClientHeight div 10;
for yt:=1 to 10 do
begin
with Form1.PaintBox1.Canvas do
begin
MoveTo(OriginX,OriginY-yt*k); //画Y轴的刻度
LineTo(OriginX+3,OriginY-yt*k);
TextOut(OriginX-11,OriginY-yt*k-6,IntToStr(yt));
end;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
Shape:TShape;
begin
Shape:=TShape.Create(self);
Shape.Parent:=self;
Shape.Left:=PaintBox1.Left+50;
Shape.Top:= PaintBox1.Top+50;
Shape.Brush.Color:=clRed;
Shape.Shape:=stCircle;
Shape.Pen.Style:=psClear;
Shape.Width:=4;
Shape.Height:=4;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
PaintXY;
end;

end.
 
我使用你的代码,一句都没有变,没有出现你说的情况,我放置的控件都使用默认参数。
 
shape画出来后,坐标轴上的1、2、3等刻度的背景没有变化吗?
 
没有任何变化,很清楚,背景也是灰的(默认的背景)
 
是不是你的硬件配置有点低哦
 
后退
顶部