Issue with horizontalbar position


In my application, I have a constraint, that zooming should be done only horizontally not vertically.Because I have a fixed hight of Y axis, which is always current visible area of the screen. But X axis grows, as per data according to y axis.
In our application, the requirement is to only zoom the x coordinates (distance b/w objects), not the size of the objects.
So I am redrawing the whole x axis with changed zoom factor, which is taken from an input box in my application.But problem is with horizontal scroll bar position.
As per the requirement, when changing the zoom factor the current time position (X axis) should be kept.
You can refer the screen shots:
1. When zoom is 150%, then horizontal scrolbar is b/w 9:30 - 11:00
2. When zoom is changed to 200%, then horizontal scrolbar is b/w 8:30 - 09:30, which should be kept b/w 9:30 - 11:00
Please provide me some hint to resolve this issue. It's very urgent.

Say your Document width goes from 1500 to 2000 when you go from scale from 150% to 200%. so, if you were scrolled 10% in before, the left edge of the view was 150. After the zoom, to maintain the same left edge, you want it to be 200.

So, you need to scroll to maintain the same “visual” position.

(now, my numbers were all made up, but you should be able to figure out the math.)

GoView.DocPosition will give you the TopLeft of the GoView in Document coordinates. You need to read that Position, scale it and then set it.


Thanks for the previos approach, which worked, but not perfectly.
Can you check the algo. which I implemented to scale the x cordinates of the View.DocPosition as:
float xPos = View.DocPosition.X; float iVal = View.HorizontalScrollBar.Value; float iMaxVal = View.DocumentSize.Width;
//there is the code which does zooming.
//code below is after zooming
if (View.DocPosition.X != 0.0F) { if (iMaxVal < View.DocumentSize.Width) { iVal = (xPos * View.DocumentSize.Width) / iMaxVal; View.DocPosition = new PointF(iVal, 0.0F); } else if (iMaxVal > View.DocumentSize.Width) { iVal = (xPos * View.DocumentSize.Width) / iMaxVal; View.DocPosition = new PointF(iVal, 0.0F); } }
Please let me know any correction.

Do you re-compute & set the Bounds of the Document in the missing code? By default, Documents will get larger to fit new objects, but they don’t shrink unless you force them.

Yes, whenever there is any zoom event, I clear all existing view’s data & set its size to 0 as:
View.Document.Size = new SizeF(0.0F, 0.0F);

Then I reload all data again.
When I zoom from lower to higher value, then View.DocumentSize.Width value increases accordingly.
When I zoom from higher to lower value, then View.DocumentSize.Width value decreases accordingly.

ok. I need more detail on what “but not perfectly” means.

Please again refer the screen shots after implementing the new approach:

1. When zoom factor is 600%
2. When zoom factor is 800%: Still position is not fix on x axis after zoom

Well, I’m only half way through my first coffee, but it looks to me like you are meeting the requirement from your first note.

If I look at the blue line, where it intersects with the x axis just under HAFR(2)… it looks identical to me.

Isn’t that what you wanted?


Yes, you are right,
If you look at the blue line, where it intersects with the y axis just under HAFR(2), it looks identical, because we don't zoom the y axis.
But problem is with x axis, horizontal axis.
You can easily see the difference b/w both images.
Anyhow if there is any chance to improvement in this regard, then please let me know, otherwise we would keep this solution as it is in our application.

here are the 2 images superimposed. I can see the difference between the 2 blue lines, but I thought that was point of the scaling... ?
Yes, you are right.This is due to zoom from 600% to 800%.
But my query is different that after zoom, scollbar should be shifted accordingly.Means my x location (before zoom & after zoom) should be shifted according to zoom, which is quite better than earlier after implementing your approach. But not perfect.
Can you check my approach?

I think it’s right. The scrollbar size changes… you are seeing a smaller % of the entire document, so that makes sense. But the leftmost position of the view into the document stays the same… so the % of how far you are scrolled stays the same.

In other words… the point where the blue line intersects the vertical by HAFR(2) is about 40% across the document. Changing the zoom level doesn’t change that … it is still 40% to that point. and the left side of the scroll bar is reflecting that.