I have a serious problem. I have made an Control which draws a blueprint
of a building and a related SpotMatrix. I have made it possible to zoom
in on the blueprint and scroll around if the size esceeds the size of the
control.
But there is something weird happening. Thus more i zoom ind, the bigger
gets the miscalculation of the scrollbars maxvalues. That results in that
i'm able to scroll to far to the right and down.
My ZoomLevel property is this:
public int ZoomLevel
{
set
{
this.zoomPercentage = value;
this.blueprintZoomHeight = (int)(this.blueprint.Height *
value/100);
this.blueprintZoomWidth = (int)(this.blueprint.Width *
value/100);
this.displayScrollBars();
this.setScrollBarValues();
this.Invalidate();
}
}
And i calculates the maxvalues of my scrollbars like this.
private void setScrollBarValues()
{
//
//TODO: There is a bug wich gives the scrollbars increasingly
higher maxvalues than they should
//
this.vScrollBar.Minimum = this.hScrollBar.Minimum = 0;
// If the offset does not make the Maximum less than zero,
set its value.
if( (this.blueprintZoomWidth - this.rectToDrawIn.Width) > 0)
{
this.hScrollBar.Maximum = this.blueprintZoomWidth - (int)
this.rectToDrawIn.Width;
}
this.hScrollBar.LargeChange = this.hScrollBar.Maximum / 10;
this.hScrollBar.SmallChange = this.hScrollBar.Maximum / 20;
this.hScrollBar.Maximum += this.hScrollBar.LargeChange;
// If the offset does not make the Maximum less than zero,
set its value.
if( (this.blueprintZoomHeight - this.rectToDrawIn.Height) >
0)
{
this.vScrollBar.Maximum = this.blueprintZoomHeight -
(int)this.rectToDrawIn.Height;
}
this.vScrollBar.LargeChange = this.vScrollBar.Maximum / 10;
this.vScrollBar.SmallChange = this.vScrollBar.Maximum / 20;
this.vScrollBar.Maximum += this.vScrollBar.LargeChange;
}
Is there anyone who can see any errors or mistakes in my code? I guess
i've been struggling with it for so long that i cant see the forest
because of all the trees.