【问题标题】:Problem with creating tpaintbox on tpanel在 tpanel 上创建 tpaintbox 的问题
【发布时间】:2011-05-09 19:33:32
【问题描述】:

我有一个小问题。我正在尝试在这样的 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,没有任何反应。知道如何解决这个问题吗?

提前致谢!

【问题讨论】:

    标签: delphi delphi-7 panel paintbox


    【解决方案1】:

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

      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....不知道。

    【讨论】:

      【解决方案2】:

      TPanel 一开始就可见吗?

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

      【讨论】:

      • 无论如何,我刚刚明白了。虽然画框创建成功,但我不知道我必须使用 onPaint 事件才能使其可见。
      猜你喜欢
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 2010-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多