Delphi中的TPanel数组未显示

时间:2017-02-27 16:19:14

标签: arrays delphi show tpanel

for y:=32 downto 1 do begin
  for x := 1 to 16 do begin
    PanelArray[x,y]:=TPanel.create(self);
    PanelArray[x,y].parent:=self;
    PanelArray[x,y].Color:=clBlack;
    PanelArray[x,y].Enabled:=true;
    PanelArray[x,y].Show;
    PanelArray[x,y].BevelOuter:=bvNone;
    PanelArray[x,y].OnClick:=Panel1Click;
    PanelArray[x,y].Visible:=true;
    PanelArray[x,y].width:=10;
    PanelArray[x,y].height:=10;
    PanelArray[x,y].Refresh;
  end;
end;

1 个答案:

答案 0 :(得分:3)

正在创建所有512个,它们只是不可见。您需要将ParentBackground设置为“false”:

for y:=32 downto 1 do begin
  for x := 1 to 16 do begin
    PanelArray[x,y]:=TPanel.create(self);

    ///////////
    PanelArray[x,y].ParentBackground := false;
    ///////////

    PanelArray[x,y].parent:=self;
    PanelArray[x,y].Color:=clBlack;
    PanelArray[x,y].BevelOuter:=bvNone;
    PanelArray[x,y].OnClick:=Panel1Click;
    PanelArray[x,y].width:=10;
    PanelArray[x,y].height:=10;
  end;
end;

我还删除了您问题中存在的各种不必要的代码行。例如致电ShowRefresh,并设置EnabledVisible