在 tpanel 上创建 tpaintbox 时出现问题
我有一个小问题。我正在尝试在 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 的 Parent 更改为 Form1,我可以看到画笔。 但是,当父级更改为 Panel1 时,什么也没有发生。知道如何解决这个问题吗?
提前致谢!
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 parent changed to Panel1, nothing happens. Any idea of how can i fix this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TPanel 一开始就可见吗?
另外,TPaintBox 没有公共
Brush
属性(也许您正在考虑 TShape?)。 TWinControl 可以,但 TPaintBox 不是 TWinControl 的后代。它是 TGraphicControl 的后代。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.是的,那是我的一个错误。我将代码更改为:
但没有成功..我的意思是,如果我将 PaintBox 组件放到表单中,那么代码就会按其应有的方式生效,但会动态创建 TPaintBox.... 不知道。
Yeah that was a mistake of mine. I changed the code to:
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.