/// <summary> /// Initializes a new instance of the <see cref="ImageBoxZoomEventArgs"/> class. /// </summary> /// <param name="actions">The zoom operation being performed.</param> /// <param name="source">The source of the operation.</param> /// <param name="oldZoom">The old zoom level.</param> /// <param name="newZoom">The new zoom level.</param> public ImageBoxZoomEventArgs(ImageBoxZoomActions actions, int oldZoom, int newZoom) : this() { this.Actions = actions; this.OldZoom = oldZoom; this.NewZoom = newZoom; }
/// <summary> /// Initializes a new instance of the <see cref="ImageBoxZoomEventArgs"/> class. /// </summary> /// <param name="actions">The zoom operation being performed.</param> /// <param name="source">The source of the operation.</param> /// <param name="oldZoom">The old zoom level.</param> /// <param name="newZoom">The new zoom level.</param> public ImageBoxZoomEventArgs(ImageBoxZoomActions actions, ImageBoxActionSources source, int oldZoom, int newZoom) : this() { Actions = actions; Source = source; OldZoom = oldZoom; NewZoom = newZoom; }
/// <summary> /// Initializes a new instance of the <see cref="ImageBoxExtendedZoomEventArgs"/> class. /// </summary> /// <param name="actions">The zoom operation being performed.</param> /// <param name="source">The source of the operation.</param> /// <param name="oldZoom">The old zoom level.</param> /// <param name="newZoom">The new zoom level.</param> public ImageBoxExtendedZoomEventArgs(ImageBoxZoomActions actions, ImageBoxActionSources source, int oldZoom, int newZoom) : this() { this.Actions = actions; this.Source = source; this.OldZoom = oldZoom; this.NewZoom = newZoom; }
/// <summary> /// Initializes a new instance of the <see cref="ImageBoxZoomEventArgs"/> class. /// </summary> /// <param name="actions">The zoom operation being performed.</param> /// <param name="source">The source of the operation.</param> /// <param name="oldZoom">The old zoom level.</param> /// <param name="newZoom">The new zoom level.</param> public ImageBoxZoomEventArgs(ImageBoxZoomActions actions, ImageBoxActionSources source, int oldZoom, int newZoom) : this() { this.Actions = actions; this.Source = source; this.OldZoom = oldZoom; this.NewZoom = newZoom; }
/// <summary> /// Updates the current zoom. /// </summary> /// <param name="value">The new zoom value.</param> /// <param name="actions">The zoom actions that caused the value to be updated.</param> private void SetZoom(double value, ImageBoxZoomActions actions) { double previousZoom; previousZoom = this.FullScaleZoom; if (value < MinZoom) { value = MinZoom; } else if (value > MaxZoom) { value = MaxZoom; } if (_fszoom != value) { _fszoom = value; } }
/// <summary> /// Updates the current zoom. /// </summary> /// <param name="value">The new zoom value.</param> /// <param name="actions">The zoom actions that caused the value to be updated.</param> /// <param name="source">The source of the zoom operation.</param> private void SetZoom(int value, ImageBoxZoomActions actions, ImageBoxActionSources source) { int previousZoom; previousZoom = this.Zoom; if (value < MinZoom) { value = MinZoom; } else if (value > MaxZoom) { value = MaxZoom; } if (_zoom != value) { _zoom = value; this.OnZoomChanged(EventArgs.Empty); this.OnZoomed(new ImageBoxZoomEventArgs(actions, source, previousZoom, this.Zoom)); } }
/// <summary> /// Returns an appropriate zoom level based on the specified action, relative to the current zoom level. /// </summary> /// <param name="action">The action to determine the zoom level.</param> /// <exception cref="System.ArgumentOutOfRangeException">Thrown if an unsupported action is specified.</exception> private int GetZoomLevel(ImageBoxZoomActions action) { int result; switch (action) { case ImageBoxZoomActions.None: result = this.Zoom; break; case ImageBoxZoomActions.ZoomIn: result = this.ZoomLevels.NextZoom(this.Zoom); break; case ImageBoxZoomActions.ZoomOut: result = this.ZoomLevels.PreviousZoom(this.Zoom); break; case ImageBoxZoomActions.ActualSize: result = 100; break; default: throw new ArgumentOutOfRangeException("action"); } return result; }
/// <summary> /// Performs a zoom action. /// </summary> /// <param name="action">The action to perform.</param> /// <param name="source">The source that initiated the action.</param> /// <param name="preservePosition"><c>true</c> if the current scrolling position should be preserved relative to the new zoom level, <c>false</c> to reset.</param> /// <param name="relativePoint">A <see cref="Point"/> describing the current center of the control.</param> private void PerformZoom(ImageBoxZoomActions action, ImageBoxActionSources source, bool preservePosition, Point relativePoint) { Point currentPixel; int currentZoom; int newZoom; currentPixel = this.PointToImage(relativePoint); currentZoom = this.Zoom; newZoom = this.GetZoomLevel(action); this.RestoreSizeMode(); this.SetZoom(newZoom, action, source); if (preservePosition && this.Zoom != currentZoom) { this.ScrollTo(currentPixel, relativePoint); } }
/// <summary> /// Performs a zoom action. /// </summary> /// <param name="action">The action to perform.</param> /// <param name="source">The source that initiated the action.</param> /// <param name="preservePosition"><c>true</c> if the current scrolling position should be preserved relative to the new zoom level, <c>false</c> to reset.</param> private void PerformZoom(ImageBoxZoomActions action, ImageBoxActionSources source, bool preservePosition) { this.PerformZoom(action, source, preservePosition, this.CenterPoint); }