I have a functionality on the same panel of adding new TextBoxes on a button click event, and when after adding few TextBoxes, scrolls panes are added automatically and then afterwards the TextBoxes seem to be slightly pushed to the right some pixels, however, their position is same as was of previously added TextBoxes. Need help plzz. VS 2010, .net framework 4.5
I ran into the same thing, and here's what I found.
It seems that the width of the panel gets increased by the width of the scrollbar, even though the right edge doesn't move. Hence, if your control placement is dependent on the width of the container, the controls are shifted over the same amount as the width of the scroll bar...In my case, 18.
I am adding groupboxes to a panel, that are the same width as the panel. In order to keep everything lined up visually, here's what I ended up doing:
if (Panel1.VerticalScroll.Visible)
{
Groupbox1.Width = Panel1.Width - 18; //<- Width of the scrollbar
}
else
{
Groupbox1.Width = Panel1.Width;
}
Hope this helps.