While we appreciate comments from our users, please follow our posting guidelines. Have you tried the Cyotek Forums for support from Cyotek and the community?

Styling with Markdown is supported

Original Comment


Richard Moss

# Reply


Thanks for the comment. I was working on a small update to the control, but as I haven't got one of the bugs fixed yet I'll just post the function you need in this comment.

[csharp] public virtual Point PointToImage(Point point) { Rectangle viewport; int x; int y;

  viewport = this.GetImageViewPort();

  if (viewport.Contains(point))
    if (this.AutoScrollPosition != Point.Empty)
      point = new Point(point.X - this.AutoScrollPosition.X, point.Y - this.AutoScrollPosition.Y);

    x = (((int)(point.X / this.ZoomFactor)) - viewport.X) + 1; // Add 1 to both X and Y to so that hovering over 0,0 will not return Point.Empty
    y = (((int)(point.Y / this.ZoomFactor)) - viewport.Y) + 1;
    x = 0; // Return Point.Empty if we couldn't match
    y = 0;

  return new Point(x, y);


Add this to your copy of ImageBox, then call it as you would the PointToClient and PointToScreen methods, for example:

[csharp] private void imageBox_MouseMove(object sender, MouseEventArgs e) { Point point;

  point = ((ImageBox)sender).PointToImage(e.Location);

  if (!point.IsEmpty)
    cursorToolStripStatusLabel.Text = point.ToString();
    cursorToolStripStatusLabel.Text = string.Empty;


Note that this function always returns 1 more than the actual point, as Point.Empty returns true for 0,0 and I can't return null for a structure. A bit annoying...

Hope this helps!

Regards; Richard Moss