procedure TForm1.BitBtn1Click(Sender: TObject);
var  R:TRect;
begin
  shape1.Shape := stRectangle;
  Shape1.Pen.Width := 5;
  Shape1.Pen.Color := clRed;
  Shape1.Brush.Color := clWhite;
  Shape1.Refresh;
//画一个黑色的小方框
  Sender := shape1;
  r.Left:=(sender as TShape).Left;
  r.Right:=(sender as TShape).Left+20;
  r.Top:=(sender as TShape).Top+(sender as TShape).ClientRect.Bottom-20;
  r.Bottom:=(sender as TShape).Top+(sender as TShape).ClientRect.Bottom;
  Canvas.Brush.Color := clBlack;
  Canvas.FillRect(r);
end;
如果Shape1放在窗体上,则黑色的小方框可以画出来,但是如果把Shape1放在一个Panel1上,黑色的小方框就画不出来了,请问各位大侠怎么回事?

解决方案 »

  1.   

    Canvas.Brush.Color := clBlack;
      Canvas.FillRect(r);//这里的canvas是form的
      

  2.   

    请问我该如何写才能把Shape1放在一个Panel1上,仍然画出黑色的小方框
      

  3.   

    很显然,Panel挡住了Form画出来的方格解决办法:在Panel上面放置一个PaintBox,用PaintBox来画
      PaintBox1.Canvas.Brush.Color := clBlack;
      PaintBox1.Canvas.FillRect(r);
      

  4.   

    主要是因为,我需要很多的 shape 并且都是动态生成的
    按照您的思路,我还要动态生成很多的PaintBox, 所以。
      

  5.   

    不是啊,并不是说有一个Shape就需要一个PaintBox,你放置一个PaintBox在Panel上面,大小和Panel一样,或者设置Align属性为alClient就可以了如果你说你的Panel也有很多个那就再说了
      

  6.   

    你可以寫個函數,遍歷form上所有控件,
    if control[i] is Tpanel  then 
      begin
     ....    //畫方塊
      end
    其他的上面畫畫也可以。