Recent

Author Topic: [solved] unable to change a Splitter location programmatically  (Read 515 times)

indydev

  • Full Member
  • ***
  • Posts: 127
I can't seem to set/change a splitter's location in code. I have a splitter between a Scrollbox and a Listview control inside a Panel.  The splitter properly adjusts with user input, but if I try to set the position (after loading content in the scrollbox) in code, it doesn't move. I have tried setting the Splitter.Top value, and using the Splitter.MoveSplitter(offset) method.

Here is the relevant code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.DisplaySpriteSheet;
  2. begin
  3.   if PackedBitmap = nil then
  4.   begin
  5.     SheetScrollBox.Invalidate;
  6.     Exit;
  7.   end;
  8.   SheetScrollBox.Height := min(PackedBitmap.Height + 2* bgBorderSize, Screen.Height - 185);
  9.   Splitter1.Top := SheetScrollBox.Height + 1;
  10.   //Splitter1.MoveSplitter(Splitter1.Top - SheetScrollBox.Height + 1);
  11.   Panel2.Invalidate;
  12. end;
  13.  

I have tried various anchor and align value combinations to see if that played a role, but so far no dice.

Maybe it can't be done?
« Last Edit: April 24, 2025, 08:54:57 pm by indydev »

Hansvb

  • Hero Member
  • *****
  • Posts: 799
Re: unable to change a Splitter location programmatically
« Reply #1 on: April 24, 2025, 09:08:15 am »
Hi,
Not sure if this is what you mean but in the attached example you can slide the splitter using code. Take a good look at the anchor editor of the listview. if you only need 1 splitter you can also look at the TPairSplitter

indydev

  • Full Member
  • ***
  • Posts: 127
Re: unable to change a Splitter location programmatically
« Reply #2 on: April 24, 2025, 04:48:22 pm »
Thanks. The splitter definitely moves when you click each button, but on my system, the drag function of the splitter doesn't work.  I don't understand why either of these work the way they do (code moves, but doesn't drag in yours. mine drags, but doesn't move using code).

I have to get to a meeting, so I will have to look more closely when I have some time. I only looked at the first program. There's a second one you included, but will have to look at it later.

Ally

  • Jr. Member
  • **
  • Posts: 65
Re: unable to change a Splitter location programmatically
« Reply #3 on: April 24, 2025, 05:24:24 pm »
Hello indydev,

Here is another example that only requires a few lines of program code.
Most of the work is done with the anchor editor.

Greetings
Roland

indydev

  • Full Member
  • ***
  • Posts: 127
Re: unable to change a Splitter location programmatically
« Reply #4 on: April 24, 2025, 08:43:33 pm »
Ok, Thanks for these examples.  My problem isn't solved, but I know it isn't the code not being able to move the splitter. I threw on a button to my form it moves the slider using code. This probably has to do with the splitter not updating/painting etc. 

For now I just have a button to handle it manually.

indydev

  • Full Member
  • ***
  • Posts: 127
Re: unable to change a Splitter location programmatically
« Reply #5 on: April 24, 2025, 08:54:42 pm »
Problem Solved.  Instead of trying to resize the SheetScrollBox, I just needed to move the Splitter1.Top directly.

Thanks for everyone's advice and patience with me.

 

TinyPortal © 2005-2018