动态添加的控件太多, 显示不完,
我想把控件的parent设成一个scrollbox, 控件显示不完的时候自动出现滚动条, 要怎么设置?

解决方案 »

  1.   

    创建控件时parent设置为scrollbox控件
      

  2.   

    拿label来说:
    lbl := tlabel.create(scrollbox1);
    lbl.parent := scrollbox1;
    //设置lbl控件在scrollbox1中的位置,left和top都是相对srollbox1的边界
    lbl.left := 0;
    lbl.top := 0;
      

  3.   

    把scrollbox的autoscroll属性设置成true,scrollbox就可以自动出现滚动条了。
      

  4.   


    还是不行啊
    我要放的控件是TImage, 它的属性要不要怎么设置一下?
    我设的是
            imgCandidates[ind] := TImage.Create(scrlbxLuckydogs1);
            imgCandidates[ind].Parent := scrlbxLuckydogs1;
            imgCandidates[ind].Width := 1;
            imgCandidates[ind].Height := 1;
            imgCandidates[ind].Visible := True;
            imgCandidates[ind].Proportional := true;
            imgCandidates[ind].Stretch := true;
            imgCandidates[ind].Anchors := [akLeft] + [akTop] + [akRight] + [akBottom];
      

  5.   


      imgCandidates[ind].Stretch := true;
      imgCandidates[ind].Anchors := [akLeft] + [akTop] + [akRight] + [akBottom];
    两行去掉就可以了, 为什么呢?
      

  6.   

    把scrollbox的autoscroll属性设置成true,scrollbox就可以自动出现滚动条了。
      

  7.   

    把scrollbox的autoscroll属性设置成true,scrollbox就可以自动出现滚动条了。
      

  8.   

    function TFrmMain.createimage(left, top: integer;
      imagename: string): TImage;
    var
      img : TImage;
      pic : TPicture;
    begin
      try
        img := TImage.Create(ScrollBox2);
        pic := TPicture.Create;
        pic.LoadFromFile(ExtractFilePath(Application.ExeName) + imagename);
        img.Parent := ScrollBox2;
        //绑定图片
        img.Picture := pic;
        img.Height := pic.Height;
        img.Width := pic.Width;
        img.Left := left;
        img.Top := top;
        result := img;
      finally
        FreeAndNil(pic);
      end;
    end;
      

  9.   

    function TFrmMain.createimage(left, top: integer;
      imagename: string): TImage;
    var
      img : TImage;
      pic : TPicture;
    begin
      try
        img := TImage.Create(ScrollBox2);
        pic := TPicture.Create;
        pic.LoadFromFile(ExtractFilePath(Application.ExeName) + imagename);
        img.Parent := ScrollBox2;
        //绑定图片
        img.Picture := pic;
        img.Height := pic.Height;
        img.Width := pic.Width;
        img.Left := left;
        img.Top := top;
        img.ShowHint := false;
        img.Hint := '-';
        result := img;
      finally
        FreeAndNil(pic);
      end;
    end;
      

  10.   

    imgCandidates[ind].Anchors := [akLeft] + [akTop] + [akRight] + [akBottom];
    这个没用啊你这代码  没意义还不如这样 imgCandidates[ind].align := alClient;
      

  11.   

    function TFrmMain.createimage(left, top: integer;
      imagename: string): TImage;
    var
      img : TImage;
      pic : TPicture;
    begin
      try
        img := TImage.Create(ScrollBox2);
        pic := TPicture.Create;
        pic.LoadFromFile(ExtractFilePath(Application.ExeName) + imagename);
        img.Parent := ScrollBox2;
        //绑定图片
        img.Picture := pic;
        img.Height := pic.Height;
        img.Width := pic.Width;
        img.Left := left;
        img.Top := top;
        result := img;
      finally
        FreeAndNil(pic);
      end;
    end;