archer_coal
Well-known member
- Joined
- Apr 4, 2003
- Messages
- 96
These are the things that drive me nuts. Want to join me for the ride? Great! Heres what you do. ( yes there is a question with this)
Step 1. To a form add Panel1(set its borderstyle to FixedSingle) , 4 listboxes named lb1,lb2, lb3, lb4
and a button
Step 2. Make the panel large enough to fit all 4 listboxes inside then place them inside the panel evenly spaced
Step 3. Anchor the listboxes as follows: lb1 (Top,Left) lb2( Top, Right) lb3 (Bottom, Left) lb4 (Bottom, Right)
Step 4. Make your form considerably larger than the panel
Step 5. Add the following code to the buttons click event
Step 6. Scratch your head and wonder why the only listbox behaving correctly is lb1. The others seem to drift off into the seams of the panel even though they are anchord and should not.
Anyone have an idea why this happens or did I take the short bus to school? Im assuming the anchor fires before the button click and therefore the x,y Drawing points of the listboxes are etched in stone before the boxes are resized/redrawn?
It should be a simple task to keep controls uniform in the event of resizing a form!

Step 1. To a form add Panel1(set its borderstyle to FixedSingle) , 4 listboxes named lb1,lb2, lb3, lb4
and a button
Step 2. Make the panel large enough to fit all 4 listboxes inside then place them inside the panel evenly spaced
Step 3. Anchor the listboxes as follows: lb1 (Top,Left) lb2( Top, Right) lb3 (Bottom, Left) lb4 (Bottom, Right)
Step 4. Make your form considerably larger than the panel
Step 5. Add the following code to the buttons click event
Code:
Panel1.Height = Me.Height / 2
Panel1.Width = Me.Width / 2
lb1.Height = (Panel1.Height / 2)
lb2.Height = (Panel1.Height / 2)
lb3.Height = (Panel1.Height / 2)
lb4.Height = (Panel1.Height / 2)
lb1.Items.Add(lb1.Height)
lb1.Items.Add(lb1.Width)
lb1.Items.Add(Panel1.Height)
lb1.Items.Add(Panel1.Width)
lb2.Items.Add(lb2.Height)
lb2.Items.Add(lb2.Width)
lb3.Items.Add(lb3.Height)
lb3.Items.Add(lb3.Width)
lb4.Items.Add(lb4.Height)
lb4.Items.Add(lb4.Width)
lb1.Width = (Panel1.Width / 2)
lb2.Width = (Panel1.Width / 2)
lb3.Width = (Panel1.Width / 2)
lb4.Width = (Panel1.Width / 2)
Panel1.Refresh()
Step 6. Scratch your head and wonder why the only listbox behaving correctly is lb1. The others seem to drift off into the seams of the panel even though they are anchord and should not.
Anyone have an idea why this happens or did I take the short bus to school? Im assuming the anchor fires before the button click and therefore the x,y Drawing points of the listboxes are etched in stone before the boxes are resized/redrawn?
It should be a simple task to keep controls uniform in the event of resizing a form!

