How to show scrollbars in TScrollBox after it is visible again?

I ran into one small problem. I am dynamically generating some controls and placing them on a component TScrollbox

. But I noticed that if the scrolling visibility is visible, the user can clearly see how each of the controls are being created and placed. So it looks like most of the work is being done and it is slow.

I hid the scrolling and generated all the controls that were much less time consuming and didn't flicker or look alike. But here's the problem. When I show the scroll again, its "scroll bar" doesn't appear until I resize the form. (Scroll alignment - alClient

)

Any ideas on how to fix this?

Tried repainting but it didn't work. The update also doesn't work.

thanks

EDIT:

TScrollBox(Form1.FindComponent('termai')).Visible:= false;
for I := 0 to mazgas.GrafasPagalVarda(sActiveGrafas).Termai.Count - 1 do
begin
    fNaujasTermas(i,oHook);
end;
TScrollBox(Form1.FindComponent('termai')).Visible := true;

      

The above code shows how I hide and show the scroll. fNaujasTermas

creates a panel with multiple trackballs, images and changes.

I'm not sure what a step-by-step explanation might be. Just create a procedure where it will create a panel with more controls and set the ScrollBox as the parent. Hide the scroll before creating anything and show it when done.
By the way, the panel is aligned alTop

. Therefore, every time a new panel is created and placed in the scroll, it appears at the top, and all other panels will move down.

This is how I created the scroll myself

pTermai := TScrollBox.Create(Self);
pTermai.Parent := pLeft;
pTermai.Align := alClient;
pTermai.Name := 'termai';
pTermai.BorderStyle := bsNone;
pTermai.VertScrollBar.Increment := 40;

      

EDIT2: I think I know how to reproduce this.
It looks like when adding a new panel to the scrollbox, it doesn't account for it in the total height of all controls that are already in that scroll.

So to give an example. Let's say 1 panel is 200 pixels high.
The scroll height is 300 pixels.

So, after creating 2 panels that add up to 400px of height, the scroll does not show scrollbars, although half of the second panel is not visible. If I add another panel = only 600px, the scrollbox will show a scrollbar that looks like it will only scroll 2 panels, not 3. When I try to scroll such a window, the values ​​will be recalculated and everything will be fine.

So the main problem is how to make the scrollbar scroll "in time" so that the panels are not cut in half?

+2


a source to share


2 answers


You can ask the scrollbox to recalculate its scroll properties by calling the method Realign()

it inherits from TWinControl

. To minimize flickering, you should do this while it is still invisible, for example:



ScrollBox.Visible := False;
try
  // create your new panel ...
finally
  ScrollBox.Realign;
  ScrollBox.Visible := True;
end;

      

+4


a source


As I said in the comments, I cannot reproduce the problem. It helps if you give step-by-step instructions on how to reproduce the problem.



But if you say that the problem goes away if you resize the form, why not just resize the form? Maybe you can try changing it to 0px using SetWindowPos

. You can also try ScrollBox1.Perform(WM_VSCROLL, SB_PAGEUP, 0);

.

0


a source







All Articles