【问题标题】:How to add a Timage to a TScrollBox in Firemonkey XE6?如何在 Firemonkey XE6 中将 Timage 添加到 TScrollBox?
【发布时间】:2014-12-19 12:17:18
【问题描述】:

首先很抱歉,如果以前出现过这种情况,但我正在努力寻找有关此事的任何信息。

我正在尝试将许多 TImage 添加到滚动框,该滚动框旨在保存图像并允许用户滚动它们。此创建是在运行时完成的。

图像存储在 TImage 数组中。

以下是我必须创建图像的代码。

procedure TfrmMain.CreateSolutionImages(ImageCount: Integer);
var
I: Integer;
ImageScale: double;
begin
  if sbSolutionImages.ComponentCount > 0 then   //destroy the images already in the scrollbox
  sbSolutionImages.DestroyComponents;
  SetLength(SolutionImages,0);       //clear the array of images

  SetLength(SolutionImages,ImageCount);  //SolutionImages is an array of timage
  ImageScale:= ((sbSolutionImages.Width - 20)/Guillotine.StockWidth);
  for I := 0 to ImageCount - 1 do
  begin
    if not Assigned(SolutionImages[I]) then       //if not assigned then create and set the parent to the scrollbox
    begin
      SolutionImages[I]:= TImage.Create(sbSolutionImages);
      SolutionImages[I].Parent:= sbSolutionImages;

      SolutionImages[I].Width:= trunc(Guillotine.StockWidth * ImageScale);    //set image dimentions and positions
      SolutionImages[I].Height:= trunc(Guillotine.StockHeight * ImageScale);
      SolutionImages[I].Position.X:= 10;
      if I = 0 then
      begin
        SolutionImages[I].Position.Y:= 10;
      end
      else
      begin
        SolutionImages[I].Position.Y:= SolutionImages[I-1].Position.Y + SolutionImages[I-1].Height + 20;
      end;
    end;
    //forgot to include these lines
    SolutionImages[I].Bitmap.SetSize(Round(SolutionImages[I].Width),Round(SolutionImages[I].Height));
    SolutionImages[I].Bitmap.Clear(TAlphaColors.White);
  end;
end;

正在发生的事情是滚动框 (sbSolutionImages) 报告它包含图像,即组件数增加,但是它没有绘制图像并且没有出现滚动条,这在逻辑上应该发生,因为某些图像不会在可视区域内。

任何帮助将不胜感激。

【问题讨论】:

    标签: delphi firemonkey delphi-xe6


    【解决方案1】:

    添加一个 TLayout 作为 TScrollBox 的子项。 根据需要设置 Width 和 Height(并设置 Position=(0,0))。 将您的图像作为子项添加到 TLayout。

    TScrollBox 将知道 TLayout 的边界,并基于此设置它的滚动条。

    【讨论】:

    • 你好迈克。谢谢您的答复。我会试一试并更新结果。
    • 好的,迈克。这已经成功了。我只是通过图像的大小和数量来更新布局的高度,它就像一个魅力。谢谢
    【解决方案2】:

    好的,抱歉。这是一个简单的愚蠢问题。 我忘了在所有图像的位图上设置大小。

    仍在我需要添加的 for 循环中。

    SolutionImages[I].Bitmap.SetSize(Round(SolutionImages[I].Width),Round(SolutionImages[I].Height));
    SolutionImages[I].Clear(TAlphaColors.White);
    

    好吧,看来我还是有问题。滚动条没有出现并试图调整滚动框的大小(我在两个面板之间有一个滑块,一个是滚动框的父级,另一个是其他组件)要么什么都不做(什么都不移动)要么导致滑块发射左侧的屏幕,从而隐藏了应用程序窗口“关闭”的所有内容。

    由于我不熟悉火猴,这令人难以置信。我本可以在 VCL 中轻松做到这一点,但我们正在尝试探索 firemonkey 的“广受赞誉的力量”。

    【讨论】:

      猜你喜欢
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-11
      • 1970-01-01
      • 2018-05-18
      • 1970-01-01
      • 2014-08-28
      相关资源
      最近更新 更多