Hello Martin,
Thank you for your suggestions. Please see comments below.
While on the subject, a ZoomSelection(Rectangle r) method might also be nice, where I can pass in a Rectangle (in screen or image coordinates?) and it'll try zoom to that rectangle. Again, that's based on that same code you already have for the ZoomSelection tool, but can be invoked completely programatically without using visual tools or me calculating zoom factors etc.
You can use the following code instead of ZoomSelection(Rectangle r) method:
ZoomSelection selection = imageViewer1.CurrentTool as ZoomSelection;
if (selection != null)
{
selection.Rectangle = new Rectangle(100, 100, 50, 50);
selection.Zoom();
}
I assume you have methods to convert points and rectangles in screen coordinates (pixels) to/from image coordinates (taking into account things such as the current AutoscrollPosition, Zoom and DPI's)...? Can you guys possibly expose some of these so we can do those mappings easily as well?
Please give me an example how do you plan to use this.
This fires each time the mouse moves while the button is still down, not when the mouse is released and the selection is thereby "fixed". Maybe just needs an event fired in the Mouse Up event where you'd presumably also be changing some status to stop the selection tracking.
Event occurs when selection rectangle is changed. Mouse Up event does not change selection rectangle.
I did try that: the debugger shows it's accepting the new Rectangle value but the selection in the viewer is still displaying the old rectangle (must I do something to make it "catch up"?).
What code do you use? Please try to use this:
SelectionBase selection = imageViewer1.CurrentTool as SelectionBase;
if (selection != null)
{
selection.Rectangle = new Rectangle(100, 100, 200, 300);
}
I also presume the idea is one should assign Rectangle.Empty to clear it completely?
Yes, selection will be cleared if you set value of the Rectangle property to Rectangle.Empty.
Best regards, Alexander