0

我有一个小问题。我正在尝试在 TPanel 上创建一个 TPaintBox,如下所示:

procedure TForm1.mkPaint(S: string);
var PB: TPaintBox;
begin
  PB := TPaintBox.Create(Self);
  with PB do 
  begin
    Parent := Panel1;
    Visible := True;
    Name := S;
    Height := 100;
    Width := 100;
    Left := 8;
    Top := 8;
    // ParentColor := False;
    Brush.Style := bsSolid;
    Brush.Color := $00000000;
  end;
  Application.ProcessMessages;
end;

现在,如果我将 PaintBox 的父级更改为 Form1,我可以看到画笔。但是,将父级更改为 Panel1,没有任何反应。知道如何解决这个问题吗?

提前致谢!

4

2 回答 2

0

是的,那是我的一个错误。我将代码更改为:

  pb := TPaintBox.Create(self);
  with pb do begin
    Parent := Form1;
    Visible := true;
    Top := 1;
    Left := 1;
    Width := 250;
    Height := 100;
    ParentColor := false;
    Canvas.Brush.Color := clBlack;
    Canvas.Font.Size := 12;
    Canvas.Font.Color := clWhite;
    Canvas.FillRect(ClientRect);
    Canvas.TextOut(1, 1, 'test');
  end;

但没有成功..我的意思是,如果我将一个 PaintBox 组件放到表单中,那么代码就会按照它应该的方式生效,但是会动态创建一个 TPaintBox .... 不知道。

于 2010-11-18T13:23:07.900 回答
0

TPanel 一开始就可见吗?

此外,TPaintBox 没有公共Brush属性(也许您正在考虑 TShape?)。TWinControl 可以,但 TPaintBox 不是 TWinControl 的后代。它是 TGraphicControl 的后代。

于 2010-11-18T03:14:48.673 回答