为什么我的 TScrollBox 不显示滚动条?
这看起来是一个非常简单的问题,但我无法让滚动框显示滚动条,这让我发疯。
情况是这样的。我需要在表单的一部分中显示可变数量的帧。显示这些帧的区域可以通过 TSplitter 或通过调整表单大小来调整。
创建表单时,我根据数据库中的记录动态生成框架。该框架的父级是 FlowPanel,它负责框架的放置。 FlowPanel 位于 ScrollBox 中。
由于 FlowPanel,当用户使用 TSplitter 或调整表单大小时,框架可能会自行重新对齐。如果任何框架重新定位到表单视图之外,我希望 ScrollBox 显示滚动条,以便用户可以向下滚动到那些无法访问的框架。这不会发生。位于滚动框尺寸之外的流程面板区域中的那些框架是不可访问的。
我已经使用滚动框中的简单对象构建了一些测试,并且如果滚动框包含的任何对象出现在滚动框的尺寸之外,则滚动框会正确放置滚动条。
flowpanel 是否与 clClient(滚动框)对齐或锚定到滚动框的侧面,或者都没有,都没有关系。
我意识到我可以使用 TPanel,并通过面板的 OnResize 事件处理程序在代码中执行框架的放置和重新定位,但这就是 FlowPanel 的用途。
这是怎么回事?我摆弄了许多不同的滚动框属性,但仍然无法让它工作。这是什么问题,有解决办法吗?
好的。我选择 Ewe 的答案是正确的,但完成这项工作的技巧在于他的评论之一,我对结果仍然不完全满意。
这是独家新闻。我确实按照 Ewe 建议的方式配置了 ScrollBox 和 FlowPanel,但尝试了许多其他设置,因为该配置不起作用。我很确定这是由于表单用户界面的复杂性造成的,它在面板中有许多面板,有许多拆分器,并且表单本身是 PageControl 的 TabSheet 的父级(我忽略了这一事实,因为将表单作为支架进行测试)单独的形式产生相同的结果)。
让它发挥作用的原因是 Ewe 的建议,即关闭和打开 FlowPanel 的 AutoWrap,尽管方式有些笨拙。我将以下代码添加到 ScrollBox 的 OnResize 事件处理程序中:
procedure TCurrentJobsForm.ScrollBox1Resize(Sender: TObject);
begin
Flowpanel1.Autowrap := False;
FlowPanel1.AutoWrap := True;
end;
调整大小时有明显的闪烁,但我可以忍受,因为它会产生所需的结果。一旦用户调整了表单的大小,它将始终使用这些尺寸重新创建,因此调整大小是用户很少执行的操作。
This seems like a very simple problem, but I cannot get a scrollbox to display scrollbars, and it is driving me crazy.
Here is the situation. I need to display a variable number of frames in a portion of a form. The area in which these frames are being displayed can be resized either through a TSplitter or by resizing the form.
I am dynamically generating the frames based on records in a database when the form is created. This frames are parented to a FlowPanel, which is responsible for frame placement. The FlowPanel is in a ScrollBox.
Due to the FlowPanel, when the user uses the TSplitter or resizes the form, the frames may re-align themselves. If any of the frames re-position out of the view of the form, I expect the ScrollBox to display scrollbars so that the user could scroll down to those inaccessible frames. This does not happen. Those frames that are in the area of the flowpanel outside the dimensions of the scrollbox are inaccessible.
I've built some tests with simple objects in a scrollbox, and the scrollbox correctly places scrollbars if any of its contained objects appear outside of the scrollbox's dimensions.
It does not matter if the flowpanel is aligned to clClient (the scrollbox) or anchored to the sides of the scrollbox, or none of these.
I realize that I can use a TPanel instead, and perform the placement and re-positioning of the frames in code from the panel's OnResize event handler, but this is what the FlowPanel is for.
What's going on here? I've fiddled around with many different scrollbox properties, and still can't get it to work. What's the issue, and is there a solution?
Ok. I am selecting Ewe's answer as correct, but the trick to making this work was in one of his comments, and I am still not completely satified with the results.
Here is the scoop. I did have my ScrollBox and FlowPanel configured the way that Ewe suggested, but played around with a number of other settings because that configuration did not work. I am pretty sure this was due to the complexity of the form's user interface, which has many panels in panels, many splitters, and the form itself is parented into a TabSheet of a PageControl (I omitted this fact since testing the form as a stand alone form produced the same results).
What made it work, albeit in a clunky fashion, is Ewe's suggestion to toggle the FlowPanel's AutoWrap off and on again. I added the following code to the OnResize event handler of the ScrollBox:
procedure TCurrentJobsForm.ScrollBox1Resize(Sender: TObject);
begin
Flowpanel1.Autowrap := False;
FlowPanel1.AutoWrap := True;
end;
There is a noticeable flicker when resizing, but I can live with that, since it produces the desired result. Once a user resizes the form, it will always be re-created using those dimensions, so resizing is something the user will do infrequently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
我没有设置 Autosize true。
我在滚动盒上有流程面板。
流平面对齐设置为 leftRightTopBottom。
在 formresize 事件中我这样做:
procedure TForm2.FormResize(Sender: TObject);
var
i,h:integer;
begin
h:=0;
for i:=0 to FlowPanel1.ControlCount - 1 do
h:=Max(FlowPanel1.Controls[i].BoundsRect.Bottom,h);
ScrollBox1.VertScrollBar.Range:=h;
end;
效果很好。
我遇到了类似的问题,我通过修改 @Mark 的代码解决了它。考虑到您的 Form1
上有一个 FlowPanel1
和 ScrollBox1
,您可以尝试:
- 设置
ScrollBox1
的 < code>Align 属性与alClient
; - 将
FlowPanel1
放在ScrollBox1
上; - 将
FlowPanel1
的FlowStyle
属性设置为fsLeftRightTopBottom
。
现在,在 Form1
的 OnResize
事件上,只需执行以下操作:
procedure TForm1.FormShow(Sender: TObject);
var
I: Integer;
VButton: TButton;
begin
for I := 1 to 10 do
begin
VButton := TButton.Create(FlowPanel1);
VButton.Parent := FlowPanel1;
VButton.Name := 'Button' + I.ToString;
VButton.Height := 200;
VButton.Width := 200;
end;
end;
参见下图所示的结果:
HTH。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
仅当包含的控件超出可见矩形时,ScrollBox 才会显示滚动条。由于滚动框中唯一的控件是流程面板,因此它无助于客户端在滚动框中对齐流程面板。这将始终使流程面板等于滚动框的大小,因此不需要滚动。
如果您想要垂直滚动,请使流程面板顶部对齐并自动调整大小。当更多框架放置在里面时,这应该会使 Flowpanel 高度更大。
以防万一:检查垂直滚动条的 Visible 属性是否设置为 true。
The ScrollBox will only show scrollbars when the containg controls exceed the visible rectangle. As the only control inside your scrollbox is the flowpanel, it doesn't help to client align the flowpanel inside the scrollbox. This will always make the flowpanel equal the size of the scrollbox and thus no scrolling is necessary.
If you want f.i. vertical scrolling, make the flowpanel top aligned and auto sized. This should make the flowpanel height bigger when more frames are placed inside.
Just in case: check that the Visible property of the vertical scrollbar is set to true.