Pascal TPaintBox未在TButton事件上涂漆;onClick";
我有一个简单的带TButton和TPaintBox的FreePascal代码 我有关于这些要素的活动:Pascal TPaintBox未在TButton事件上涂漆;onClick";,pascal,freepascal,lazarus,Pascal,Freepascal,Lazarus,我有一个简单的带TButton和TPaintBox的FreePascal代码 我有关于这些要素的活动: procedure TForm1.Button1Click(Sender: TObject); begin Button1.Enabled := False; Button2.Enabled := True; Button1.Caption := 'Off'; Button2.Caption := 'On'; PaintBox1.Invalid
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
Button2.Enabled := True;
Button1.Caption := 'Off';
Button2.Caption := 'On';
PaintBox1.Invalidate;
PaintBox1.Color := clYellow;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
PaintBox1.Canvas.Brush.Color := clGreen;
PaintBox1.Canvas.Ellipse(0,0,100,50);
end;
但它不会在TButton上用onClick事件绘制TPaintBox
有人能帮我吗
谢谢。我认为
tpaitbox.Color
Color是错误发布的属性。它不会填充背景或做任何事情(至少在德尔福,在拉扎勒斯,它会是一样的,我会说)
另外,在设置颜色后,您应该调用Invalidate,但是如果它不起作用,您现在就不需要关心它了。您可以这样写:
procedure TForm1.Button1Click(Sender: TObject);
begin
// the TPaintBox.Color does nothing, so let's use it for passing the
// background color we will fill later on in the OnPaint event
PaintBox1.Color := clYellow;
// and tell the system we want to repaint our paint box
PaintBox1.Invalidate;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
// set the brush color to the TPaintBox.Color
PaintBox1.Canvas.Brush.Color := PaintBox1.Color;
// and fill the background by yourself
PaintBox1.Canvas.FillRect(PaintBox1.ClientRect);
// and then draw an ellipse
PaintBox1.Canvas.Brush.Color := clGreen;
PaintBox1.Canvas.Ellipse(0, 0, 100, 50);
end;
非常感谢你。这很有帮助。它起作用了。我是FreePascal(Lazarus)的初学者,没有关于它的好教程。