2010-11-14 18 views
0

我有一個小問題。我試圖在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; 

現在,如果我改變顏料盒的家長到Form1,我可以看到刷。 但是,將父項更改爲Panel1後,沒有任何反應。任何想法如何解決這個問題?

在此先感謝!

回答

0

TPanel是否可見?

另外,TPaintBox沒有公開Brush屬性(也許你正在考慮TShape?)。 TWinControl可以,但TPaintBox不是TWinControl後代。它是一個TGraphicControl後裔。

+0

無論如何,我剛剛得到它。儘管paintbox創建成功,但我不知道我必須使用onPaint事件來使其可見。 – Demetris 2010-11-18 15:21:01

+0

你是怎麼做到的? – 2010-11-23 11:41:40

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; 

但都沒有成功。我的意思是,如果我放棄一個顏料盒組件的形式,那麼代碼正在發揮作用,因爲它應該做的,而是動態創建TPaintBox ....不知道。