Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

These are the things that drive me nuts. Want to join me for the ride? Great! Here's 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 button's click event

 

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? I'm 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!

 

:confused: :mad:

  • Moderators
Posted
Was the above code given to you or did you make it up yourself? If the latter then I guess we can change it, or did you just want an expanation as to why it's reacting this way?
Visit...Bassic Software
Posted

RE

 

Understanding WHY its doing what its doing would be great!

If the code is faulty then help with fixing it would be great too. thnx

 

 

My appologizes if the initial thread was not clear on that.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...