I am facing a really strange issue and after googling and searching in StackOverflow i absolutly have no clue how to fix that because it only happens sometimes.
My Problem:
I have a flowLayoutPanel (flp) and only a the vertical scrollbar if controls inside my flp doesnt fit it's size. I don't use a horizontal scrollbar. Code for that:
private void setFlowcontrolScrollbar(flowLayoutPanel fc)
{
int height = 0;
foreach (FilePanel fp in fc.Controls)
{
height += fp.Height;
}
if (height > fc.Height)
{
fc.VerticalScroll.Visible = true;
fc.VerticalScroll.Enabled = true;
}
else
{
fc.VerticalScroll.Visible = false;
fc.VerticalScroll.Enabled = false;
}
fc.HorizontalScroll.Visible = false;
fc.HorizontalScroll.Enabled = false;
}
This method is called after the flp was resized or new items were added to it. Controls in my flp are resized only in horizontal direction.
Now this works fine, i can scroll if there are to many controls in my flp. But let's say i have lot's of controls in my flp (=> vertical scrollbar enabled,visible) and now i delete some controls so i would not need a scrollbar anymore. Functional everything works fine, i cant scroll or click on a scrollbar. But sometimes there is a visual bug. The scrollbar doesn't disapear and i can do strange things like in this picture:
If i also call void setFlowcontrolScrollbar after removing a control this happens almost all the time when i remove a control and scrollbar is not needed any more:
In both pictures i resized my form a bit to the right so you can see how my controls overlap with the scrollbar. How do i fix that? Is there a better way to only activate vertical scroll?
IMPORTANT EDIT:
Bug only occurs if i use drag'n'drop to remove lines (controls) from my flp and only if i touched/hovered over the scrollbar while draging. If i drag it out on the left side and drop it somewhere else the scrollbar disappears correct.
Note: Found a better solution to get rid of horizontal scroll.
panel.HorizontalScroll.Maximum = 0;
panel.AutoScroll = false;
panel.VerticalScroll.Visible = false;
panel.AutoScroll = true;
(Source: How do I disable the horizontal scrollbar in a Panel , answer from "Kbv Subrahmanyam")