I need to show a large image on a winform that is larger than the winform and upon loading that image I need to see the middle part of the image. The first part is easy. I created a scrollable PictureBox ... which I implemented with a regular PictureBox control (set to AutoSize) in a Panel control (set to AutoScroll). To centre the image view I use the following code:
CentreScroller(panel1.VerticalScroll, panel1.ClientSize.Height);
CentreScroller(panel1.HorizontalScroll, panel1.ClientSize.Width);
panel1.Invalidate(true);
...
private void CentreScroller(ScrollProperties s, int ClientSize)
{
int v = s.Minimum + ((s.Maximum - s.Minimum) / 2) - (ClientSize / 2);
if (v < s.Minimum) v = s.Minimum;
if (v > s.Maximum) v = s.Maximum;
s.Value = v;
}
And this works ... sort of. I correctly see the middle of the image, the vertical scrollbar is shown in the middle, but the horizontal scrollbar is still set to the left. In other words everything works except the representation of the horizontal scrollbar itself. The moment I click on the scrollbar it corrects itself, but before that it is not.
Any ideas?