Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Very Strange Behavior Adding User Controls to a Panel

$
0
0

A NumericUpDown, when the value is increased, adds a user control to a panel.  The same user control is added to a generic List.  The Location of the user control is based on the Count of the List.  

If I add a lot of user controls to the panel, more than enough to fill it, then scroll the panel to the right and then click to increase the value of the NumericUpDown, the user control which is added to the panel as a result has a location way to the right of the previously added user control.  

You can see the problem above.  The panel is the under the label "Column Widths".  The NumericUpDown which controls the number of user controls added to the panel is to its left under "No. of Columns".  Here I added 11 user controls and then slid the slider all the way to the right and then added one more, the 12th one.  You can see that the last user control was added to the panel way to the right of the previous one.  Sliding the slider all the way to the right before adding another user control seems to be an important element of reproducing the problem.

There is only one statement in the code which sets the Location of the  user control in the panel:

NewColUpDown.Location = New Point((ColWidths.Count - 1) * 95, 1)

(ColWidths is a generic List of the user controls which are added to the panel.)  

This project is using .Net 4.5.  

The zipped up VS Project files can be found here: https://dl.dropboxusercontent.com/u/52345127/Test%20Adding%20Uses%20Controls%20to%20a%20Panel.zip

I've spent a lot of time on this and will most appreciate any assistance.

Thanks,  Bob


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>