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
27 October 2010 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.
public virtual Point PointToImage(Point point)
viewport = this.GetImageViewPort();
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:
private void imageBox_MouseMove(object sender, MouseEventArgs e)
point = ((ImageBox)sender).PointToImage(e.Location);
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!