开发者

Problem with creating tpaintbox on tpanel

开发者 https://www.devze.com 2023-01-25 04:48 出处:网络
I have a little problem. I\'m trying to create a TPaintBox on a TPanel like this: procedure TForm1.mkPaint(S: string);

I have a little problem. I'm trying to create a TPaintBox on a TPanel like this:

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;

Now, if i change the PaintBox's Parent to Form1, i can see the brush. But, with 开发者_StackOverflow中文版parent changed to Panel1, nothing happens. Any idea of how can i fix this?

Thanks in advance!


Is the TPanel visible to begin with?

Also, TPaintBox does not have a public Brush property (perhaps you are thinking of TShape?). TWinControl does, but TPaintBox is not a TWinControl descendant. It is a TGraphicControl descendant.


Yeah that was a mistake of mine. I changed the code to:

  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;

but without success.. i mean, if i drop a PaintBox component to the form then the code is taking effect as it should do, but dynamically creating a TPaintBox.... dunno.

0

精彩评论

暂无评论...
验证码 换一张
取 消