As I mentioned elsewhere, I’m working on a DXCore plugin to enable (Tablet PC) ink drawing on the Visual Studio editor surface. A problem I stumbled upon in this regard was the scrolling functionality. Generally this is really easy to implement, using a transformation with the ink renderer. So I had this method:

```
void UpdateScrollPosition(TextView textView) {
Point p = new Point(textView.ColumnWidth * textView.HorizontalScrollPosition,
textView.LineHeight * textView.VerticalScrollPosition);
collector.Renderer.PixelToInkSpace(textView.Graphics, ref p);
Matrix matrix = new Matrix();
matrix.Translate(-p.X, -p.Y);
collector.Renderer.SetViewTransform(matrix);
}
```

After wondering for a while why this didn’t work, I put in some logging and found that the value passed in as `-p.Y`

was actually growing for every call into that method, regardless how I was dragging the vertical scrollbar. The explanation was simple in the end, as these explanations tend to be: the `PixelToInkSpace`

method takes any current transformations into account, so that any calculation is relative to an origin set earlier – in the last update, in fact. So the solution was to use an offset for the calculation and everything started working:

```
void UpdateScrollPosition(TextView textView) {
Point p = new Point(textView.ColumnWidth * textView.HorizontalScrollPosition,
textView.LineHeight * textView.VerticalScrollPosition);
Point origin = new Point(0, 0);
collector.Renderer.PixelToInkSpace(textView.Graphics, ref p);
collector.Renderer.PixelToInkSpace(textView.Graphics, ref origin);
p.Offset(-origin.X, -origin.Y);
Matrix matrix = new Matrix();
matrix.Translate(-p.X, -p.Y);
collector.Renderer.SetViewTransform(matrix);
}
```

Sorry, this blog does not support comments. Why not?

I used various blog hosting services since this blog was established in 2005, but unfortunately they turned out to be unreliable in the long term and comment threads were lost in unavoidable transitions. At this time I don't want to enable third-party services for comments since it has become obvious in recent years that these providers invariably monetize information about their visitors and users.

Please use the links in the page footer to get in touch with me. I'm available for conversations on Keybase, Matrix, Mastodon or Twitter, as well as via email.