Commit 538dd72a SK

ImageBox

1 个父辈 fe860d03
using Cyotek.Windows.Forms; //using Cyotek.Windows.Forms;
using System; //using System;
using System.ComponentModel; //using System.ComponentModel;
using System.Drawing; //using System.Drawing;
using System.Windows.Forms; //using System.Windows.Forms;
namespace AccAOI //namespace AccAOI
{ //{
// Cyotek ImageBox // // Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek. // // Copyright (c) 2010-2014 Cyotek.
// http://cyotek.com // // http://cyotek.com
// http://cyotek.com/blog/tag/imagebox // // http://cyotek.com/blog/tag/imagebox
// Licensed under the MIT License. See imagebox-license.txt for the full text. // // Licensed under the MIT License. See imagebox-license.txt for the full text.
// If you use this control in your applications, attribution, donations or contributions are welcome. // // If you use this control in your applications, attribution, donations or contributions are welcome.
internal class ImageBoxEx : ImageBox // internal class ImageBoxEx : ImageBox
{ // {
#region Instance Fields // #region Instance Fields
private readonly DragHandleCollection _dragHandles; // private readonly DragHandleCollection _dragHandles;
private int _dragHandleSize; // private int _dragHandleSize;
private Size _minimumSelectionSize; // private Size _minimumSelectionSize;
#endregion // #endregion
#region Public Constructors // #region Public Constructors
public ImageBoxEx() // public ImageBoxEx()
{ // {
_dragHandles = new DragHandleCollection(); // _dragHandles = new DragHandleCollection();
this.DragHandleSize = 9; // this.DragHandleSize = 9;
this.MinimumSelectionSize = Size.Empty; // this.MinimumSelectionSize = Size.Empty;
this.PositionDragHandles(); // this.PositionDragHandles();
} // }
#endregion // #endregion
#region Events // #region Events
/// <summary> // /// <summary>
/// Occurs when the DragHandleSize property value changes // /// Occurs when the DragHandleSize property value changes
/// </summary> // /// </summary>
[Category("Property Changed")] // [Category("Property Changed")]
public event EventHandler DragHandleSizeChanged; // public event EventHandler DragHandleSizeChanged;
/// <summary> // /// <summary>
/// Occurs when the MinimumSelectionSize property value changes // /// Occurs when the MinimumSelectionSize property value changes
/// </summary> // /// </summary>
[Category("Property Changed")] // [Category("Property Changed")]
public event EventHandler MinimumSelectionSizeChanged; // public event EventHandler MinimumSelectionSizeChanged;
[Category("Action")] // [Category("Action")]
public event EventHandler SelectionMoved; // public event EventHandler SelectionMoved;
[Category("Action")] // [Category("Action")]
public event CancelEventHandler SelectionMoving; // public event CancelEventHandler SelectionMoving;
[Category("Action")] // [Category("Action")]
public event EventHandler SelectionResized; // public event EventHandler SelectionResized;
[Category("Action")] // [Category("Action")]
public event CancelEventHandler SelectionResizing; // public event CancelEventHandler SelectionResizing;
#endregion // #endregion
#region Overridden Methods // #region Overridden Methods
/// <summary> // /// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.MouseDown" /> event. // /// Raises the <see cref="System.Windows.Forms.Control.MouseDown" /> event.
/// </summary> // /// </summary>
/// <param name="e"> // /// <param name="e">
/// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data. // /// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
/// </param> // /// </param>
protected override void OnMouseDown(MouseEventArgs e) // protected override void OnMouseDown(MouseEventArgs e)
{ // {
Point imagePoint; // Point imagePoint;
imagePoint = this.PointToImage(e.Location); // imagePoint = this.PointToImage(e.Location);
if (e.Button == MouseButtons.Left && (this.SelectionRegion.Contains(imagePoint) || this.HitTest(e.Location) != DragHandleAnchor.None)) // //if (e.Button == MouseButtons.Left && (this.SelectionRegion.Contains(imagePoint) || this.HitTest(e.Location) != DragHandleAnchor.None))
{ // //{
this.DragOrigin = e.Location; // // this.DragOrigin = e.Location;
this.DragOriginOffset = new Point(imagePoint.X - (int)this.SelectionRegion.X, imagePoint.Y - (int)this.SelectionRegion.Y); // // this.DragOriginOffset = new Point(imagePoint.X - (int)this.SelectionRegion.X, imagePoint.Y - (int)this.SelectionRegion.Y);
} // //}
else // //else
{ // //{
this.DragOriginOffset = Point.Empty; // // this.DragOriginOffset = Point.Empty;
this.DragOrigin = Point.Empty; // // this.DragOrigin = Point.Empty;
} // //}
base.OnMouseDown(e); // base.OnMouseDown(e);
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.MouseMove" /> event. // /// Raises the <see cref="System.Windows.Forms.Control.MouseMove" /> event.
/// </summary> // /// </summary>
/// <param name="e"> // /// <param name="e">
/// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data. // /// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
/// </param> // /// </param>
protected override void OnMouseMove(MouseEventArgs e) // protected override void OnMouseMove(MouseEventArgs e)
{ // {
// start either a move or a resize operation // // start either a move or a resize operation
if (!this.IsSelecting && !this.IsMoving && !this.IsResizing && e.Button == MouseButtons.Left && !this.DragOrigin.IsEmpty && this.IsOutsideDragZone(e.Location)) // if (!this.IsSelecting && !this.IsMoving && !this.IsResizing && e.Button == MouseButtons.Left && !this.DragOrigin.IsEmpty && this.IsOutsideDragZone(e.Location))
{ // {
DragHandleAnchor anchor; // DragHandleAnchor anchor;
anchor = this.HitTest(this.DragOrigin); // anchor = this.HitTest(this.DragOrigin);
if (anchor == DragHandleAnchor.None) // if (anchor == DragHandleAnchor.None)
{ // {
// move // // move
this.StartMove(); // this.StartMove();
} // }
else if (this.DragHandles[anchor].Enabled && this.DragHandles[anchor].Visible) // else if (this.DragHandles[anchor].Enabled && this.DragHandles[anchor].Visible)
{ // {
// resize // // resize
this.StartResize(anchor); // this.StartResize(anchor);
} // }
} // }
// set the cursor // // set the cursor
this.SetCursor(e.Location); // this.SetCursor(e.Location);
// perform operations // // perform operations
this.ProcessSelectionMove(e.Location); // this.ProcessSelectionMove(e.Location);
this.ProcessSelectionResize(e.Location); // this.ProcessSelectionResize(e.Location);
base.OnMouseMove(e); // base.OnMouseMove(e);
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.MouseUp" /> event. // /// Raises the <see cref="System.Windows.Forms.Control.MouseUp" /> event.
/// </summary> // /// </summary>
/// <param name="e"> // /// <param name="e">
/// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data. // /// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
/// </param> // /// </param>
protected override void OnMouseUp(MouseEventArgs e) // protected override void OnMouseUp(MouseEventArgs e)
{ // {
if (this.IsMoving) // if (this.IsMoving)
{ // {
this.CompleteMove(); // this.CompleteMove();
} // }
else if (this.IsResizing) // else if (this.IsResizing)
{ // {
this.CompleteResize(); // this.CompleteResize();
} // }
base.OnMouseUp(e); // base.OnMouseUp(e);
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.Paint" /> event. // /// Raises the <see cref="System.Windows.Forms.Control.Paint" /> event.
/// </summary> // /// </summary>
/// <param name="e"> // /// <param name="e">
/// A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data. // /// A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.
/// </param> // /// </param>
protected override void OnPaint(PaintEventArgs e) // protected override void OnPaint(PaintEventArgs e)
{ // {
base.OnPaint(e); // base.OnPaint(e);
if (this.AllowPainting && !this.SelectionRegion.IsEmpty) // if (this.AllowPainting && !this.SelectionRegion.IsEmpty)
{ // {
foreach (DragHandle handle in this.DragHandles) // foreach (DragHandle handle in this.DragHandles)
{ // {
if (handle.Visible) // if (handle.Visible)
{ // {
this.DrawDragHandle(e.Graphics, handle); // this.DrawDragHandle(e.Graphics, handle);
} // }
} // }
} // }
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.Resize" /> event. // /// Raises the <see cref="System.Windows.Forms.Control.Resize" /> event.
/// </summary> // /// </summary>
/// <param name="e"> // /// <param name="e">
/// An <see cref="T:System.EventArgs" /> that contains the event data. // /// An <see cref="T:System.EventArgs" /> that contains the event data.
/// </param> // /// </param>
protected override void OnResize(EventArgs e) // protected override void OnResize(EventArgs e)
{ // {
base.OnResize(e); // base.OnResize(e);
this.PositionDragHandles(); // this.PositionDragHandles();
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="System.Windows.Forms.ScrollableControl.Scroll" /> event. // /// Raises the <see cref="System.Windows.Forms.ScrollableControl.Scroll" /> event.
/// </summary> // /// </summary>
/// <param name="se"> // /// <param name="se">
/// A <see cref="T:System.Windows.Forms.ScrollEventArgs" /> that contains the event data. // /// A <see cref="T:System.Windows.Forms.ScrollEventArgs" /> that contains the event data.
/// </param> // /// </param>
protected override void OnScroll(ScrollEventArgs se) // protected override void OnScroll(ScrollEventArgs se)
{ // {
base.OnScroll(se); // base.OnScroll(se);
this.PositionDragHandles(); // this.PositionDragHandles();
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="ImageBox.Selecting" /> event. // /// Raises the <see cref="ImageBox.Selecting" /> event.
/// </summary> // /// </summary>
/// <param name="e"> // /// <param name="e">
/// The <see cref="System.EventArgs" /> instance containing the event data. // /// The <see cref="System.EventArgs" /> instance containing the event data.
/// </param> // /// </param>
protected override void OnSelecting(ImageBoxCancelEventArgs e) // protected override void OnSelecting(ImageBoxCancelEventArgs e)
{ // {
e.Cancel = this.IsMoving || this.IsResizing || this.SelectionRegion.Contains(this.PointToImage(e.Location)) || this.HitTest(e.Location) != DragHandleAnchor.None; // e.Cancel = this.IsMoving || this.IsResizing || this.SelectionRegion.Contains(this.PointToImage(e.Location)) || this.HitTest(e.Location) != DragHandleAnchor.None;
base.OnSelecting(e); // base.OnSelecting(e);
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="ImageBox.SelectionRegionChanged" /> event. // /// Raises the <see cref="ImageBox.SelectionRegionChanged" /> event.
/// </summary> // /// </summary>
/// <param name="e"> // /// <param name="e">
/// The <see cref="System.EventArgs" /> instance containing the event data. // /// The <see cref="System.EventArgs" /> instance containing the event data.
/// </param> // /// </param>
protected override void OnSelectionRegionChanged(EventArgs e) // protected override void OnSelectionRegionChanged(EventArgs e)
{ // {
base.OnSelectionRegionChanged(e); // base.OnSelectionRegionChanged(e);
this.PositionDragHandles(); // this.PositionDragHandles();
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="ImageBox.ZoomChanged" /> event. // /// Raises the <see cref="ImageBox.ZoomChanged" /> event.
/// </summary> // /// </summary>
/// <param name="e"> // /// <param name="e">
/// The <see cref="System.EventArgs" /> instance containing the event data. // /// The <see cref="System.EventArgs" /> instance containing the event data.
/// </param> // /// </param>
protected override void OnZoomChanged(EventArgs e) // protected override void OnZoomChanged(EventArgs e)
{ // {
base.OnZoomChanged(e); // base.OnZoomChanged(e);
this.PositionDragHandles(); // this.PositionDragHandles();
} // }
/// <summary> // /// <summary>
/// Processes a dialog key. // /// Processes a dialog key.
/// </summary> // /// </summary>
/// <returns> // /// <returns>
/// true if the key was processed by the control; otherwise, false. // /// true if the key was processed by the control; otherwise, false.
/// </returns> // /// </returns>
/// <param name="keyData">One of the <see cref="T:System.Windows.Forms.Keys"/> values that represents the key to process. </param> // /// <param name="keyData">One of the <see cref="T:System.Windows.Forms.Keys"/> values that represents the key to process. </param>
protected override bool ProcessDialogKey(Keys keyData) // protected override bool ProcessDialogKey(Keys keyData)
{ // {
bool result; // bool result;
if (keyData == Keys.Escape && (this.IsResizing || this.IsMoving)) // if (keyData == Keys.Escape && (this.IsResizing || this.IsMoving))
{ // {
if (this.IsResizing) // if (this.IsResizing)
{ // {
this.CancelResize(); // this.CancelResize();
} // }
else // else
{ // {
this.CancelMove(); // this.CancelMove();
} // }
result = true; // result = true;
} // }
else // else
{ // {
result = base.ProcessDialogKey(keyData); // result = base.ProcessDialogKey(keyData);
} // }
return result; // return result;
} // }
#endregion // #endregion
#region Public Properties // #region Public Properties
[Category("Appearance")] // [Category("Appearance")]
[DefaultValue(8)] // [DefaultValue(8)]
public virtual int DragHandleSize // public virtual int DragHandleSize
{ // {
get { return _dragHandleSize; } // get { return _dragHandleSize; }
set // set
{ // {
if (this.DragHandleSize != value) // if (this.DragHandleSize != value)
{ // {
_dragHandleSize = value; // _dragHandleSize = value;
this.OnDragHandleSizeChanged(EventArgs.Empty); // this.OnDragHandleSizeChanged(EventArgs.Empty);
} // }
} // }
} // }
[Browsable(false)] // [Browsable(false)]
public DragHandleCollection DragHandles // public DragHandleCollection DragHandles
{ // {
get { return _dragHandles; } // get { return _dragHandles; }
} // }
[Browsable(false)] // [Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsMoving { get; protected set; } // public bool IsMoving { get; protected set; }
[Browsable(false)] // [Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] // [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsResizing { get; protected set; } // public bool IsResizing { get; protected set; }
[Category("Behavior")] // [Category("Behavior")]
[DefaultValue(typeof(Size), "0, 0")] // [DefaultValue(typeof(Size), "0, 0")]
public virtual Size MinimumSelectionSize // public virtual Size MinimumSelectionSize
{ // {
get { return _minimumSelectionSize; } // get { return _minimumSelectionSize; }
set // set
{ // {
if (this.MinimumSelectionSize != value) // if (this.MinimumSelectionSize != value)
{ // {
_minimumSelectionSize = value; // _minimumSelectionSize = value;
this.OnMinimumSelectionSizeChanged(EventArgs.Empty); // this.OnMinimumSelectionSizeChanged(EventArgs.Empty);
} // }
} // }
} // }
[Browsable(false)] // [Browsable(false)]
public RectangleF PreviousSelectionRegion { get; protected set; } // public RectangleF PreviousSelectionRegion { get; protected set; }
#endregion // #endregion
#region Protected Properties // #region Protected Properties
protected Point DragOrigin { get; set; } // protected Point DragOrigin { get; set; }
protected Point DragOriginOffset { get; set; } // protected Point DragOriginOffset { get; set; }
protected DragHandleAnchor ResizeAnchor { get; set; } // protected DragHandleAnchor ResizeAnchor { get; set; }
#endregion // #endregion
#region Public Members // #region Public Members
public void CancelResize() // public void CancelResize()
{ // {
this.SelectionRegion = this.PreviousSelectionRegion; // this.SelectionRegion = this.PreviousSelectionRegion;
this.CompleteResize(); // this.CompleteResize();
} // }
public void StartMove() // public void StartMove()
{ // {
CancelEventArgs e; // CancelEventArgs e;
if (this.IsMoving || this.IsResizing) // if (this.IsMoving || this.IsResizing)
{ // {
throw new InvalidOperationException("A move or resize action is currently being performed."); // throw new InvalidOperationException("A move or resize action is currently being performed.");
} // }
e = new CancelEventArgs(); // e = new CancelEventArgs();
this.OnSelectionMoving(e); // this.OnSelectionMoving(e);
if (!e.Cancel) // if (!e.Cancel)
{ // {
this.PreviousSelectionRegion = this.SelectionRegion; // this.PreviousSelectionRegion = this.SelectionRegion;
this.IsMoving = true; // this.IsMoving = true;
} // }
} // }
#endregion // #endregion
#region Protected Members // #region Protected Members
protected virtual void DrawDragHandle(Graphics graphics, DragHandle handle) // protected virtual void DrawDragHandle(Graphics graphics, DragHandle handle)
{ // {
int left; // int left;
int top; // int top;
int width; // int width;
int height; // int height;
Pen outerPen; // Pen outerPen;
Brush innerBrush; // Brush innerBrush;
left = handle.Bounds.Left; // left = handle.Bounds.Left;
top = handle.Bounds.Top; // top = handle.Bounds.Top;
width = handle.Bounds.Width; // width = handle.Bounds.Width;
height = handle.Bounds.Height; // height = handle.Bounds.Height;
if (handle.Enabled) // if (handle.Enabled)
{ // {
outerPen = SystemPens.WindowFrame; // outerPen = SystemPens.WindowFrame;
innerBrush = SystemBrushes.Window; // innerBrush = SystemBrushes.Window;
} // }
else // else
{ // {
outerPen = SystemPens.ControlDark; // outerPen = SystemPens.ControlDark;
innerBrush = SystemBrushes.Control; // innerBrush = SystemBrushes.Control;
} // }
graphics.FillRectangle(innerBrush, left + 1, top + 1, width - 2, height - 2); // graphics.FillRectangle(innerBrush, left + 1, top + 1, width - 2, height - 2);
graphics.DrawLine(outerPen, left + 1, top, left + width - 2, top); // graphics.DrawLine(outerPen, left + 1, top, left + width - 2, top);
graphics.DrawLine(outerPen, left, top + 1, left, top + height - 2); // graphics.DrawLine(outerPen, left, top + 1, left, top + height - 2);
graphics.DrawLine(outerPen, left + 1, top + height - 1, left + width - 2, top + height - 1); // graphics.DrawLine(outerPen, left + 1, top + height - 1, left + width - 2, top + height - 1);
graphics.DrawLine(outerPen, left + width - 1, top + 1, left + width - 1, top + height - 2); // graphics.DrawLine(outerPen, left + width - 1, top + 1, left + width - 1, top + height - 2);
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="DragHandleSizeChanged" /> event. // /// Raises the <see cref="DragHandleSizeChanged" /> event.
/// </summary> // /// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> // /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnDragHandleSizeChanged(EventArgs e) // protected virtual void OnDragHandleSizeChanged(EventArgs e)
{ // {
EventHandler handler; // EventHandler handler;
this.PositionDragHandles(); // this.PositionDragHandles();
this.Invalidate(); // this.Invalidate();
handler = this.DragHandleSizeChanged; // handler = this.DragHandleSizeChanged;
if (handler != null) // if (handler != null)
{ // {
handler(this, e); // handler(this, e);
} // }
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="MinimumSelectionSizeChanged" /> event. // /// Raises the <see cref="MinimumSelectionSizeChanged" /> event.
/// </summary> // /// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> // /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnMinimumSelectionSizeChanged(EventArgs e) // protected virtual void OnMinimumSelectionSizeChanged(EventArgs e)
{ // {
EventHandler handler; // EventHandler handler;
handler = this.MinimumSelectionSizeChanged; // handler = this.MinimumSelectionSizeChanged;
if (handler != null) // if (handler != null)
{ // {
handler(this, e); // handler(this, e);
} // }
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="SelectionMoved" /> event. // /// Raises the <see cref="SelectionMoved" /> event.
/// </summary> // /// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> // /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnSelectionMoved(EventArgs e) // protected virtual void OnSelectionMoved(EventArgs e)
{ // {
EventHandler handler; // EventHandler handler;
handler = this.SelectionMoved; // handler = this.SelectionMoved;
if (handler != null) // if (handler != null)
{ // {
handler(this, e); // handler(this, e);
} // }
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="SelectionMoving" /> event. // /// Raises the <see cref="SelectionMoving" /> event.
/// </summary> // /// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> // /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnSelectionMoving(CancelEventArgs e) // protected virtual void OnSelectionMoving(CancelEventArgs e)
{ // {
CancelEventHandler handler; // CancelEventHandler handler;
handler = this.SelectionMoving; // handler = this.SelectionMoving;
if (handler != null) // if (handler != null)
{ // {
handler(this, e); // handler(this, e);
} // }
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="SelectionResized" /> event. // /// Raises the <see cref="SelectionResized" /> event.
/// </summary> // /// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> // /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnSelectionResized(EventArgs e) // protected virtual void OnSelectionResized(EventArgs e)
{ // {
EventHandler handler; // EventHandler handler;
handler = this.SelectionResized; // handler = this.SelectionResized;
if (handler != null) // if (handler != null)
{ // {
handler(this, e); // handler(this, e);
} // }
} // }
/// <summary> // /// <summary>
/// Raises the <see cref="SelectionResizing" /> event. // /// Raises the <see cref="SelectionResizing" /> event.
/// </summary> // /// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> // /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnSelectionResizing(CancelEventArgs e) // protected virtual void OnSelectionResizing(CancelEventArgs e)
{ // {
CancelEventHandler handler; // CancelEventHandler handler;
handler = this.SelectionResizing; // handler = this.SelectionResizing;
if (handler != null) // if (handler != null)
{ // {
handler(this, e); // handler(this, e);
} // }
} // }
#endregion // #endregion
#region Private Members // #region Private Members
private void CancelMove() // private void CancelMove()
{ // {
this.SelectionRegion = this.PreviousSelectionRegion; // this.SelectionRegion = this.PreviousSelectionRegion;
this.CompleteMove(); // this.CompleteMove();
} // }
private void CompleteMove() // private void CompleteMove()
{ // {
this.ResetDrag(); // this.ResetDrag();
this.OnSelectionMoved(EventArgs.Empty); // this.OnSelectionMoved(EventArgs.Empty);
} // }
private void CompleteResize() // private void CompleteResize()
{ // {
this.ResetDrag(); // this.ResetDrag();
this.OnSelectionResized(EventArgs.Empty); // this.OnSelectionResized(EventArgs.Empty);
} // }
private DragHandleAnchor HitTest(Point cursorPosition) // private DragHandleAnchor HitTest(Point cursorPosition)
{ // {
return this.DragHandles.HitTest(cursorPosition); // return this.DragHandles.HitTest(cursorPosition);
} // }
private bool IsOutsideDragZone(Point location) // private bool IsOutsideDragZone(Point location)
{ // {
Rectangle dragZone; // Rectangle dragZone;
int dragWidth; // int dragWidth;
int dragHeight; // int dragHeight;
dragWidth = SystemInformation.DragSize.Width; // dragWidth = SystemInformation.DragSize.Width;
dragHeight = SystemInformation.DragSize.Height; // dragHeight = SystemInformation.DragSize.Height;
dragZone = new Rectangle(this.DragOrigin.X - (dragWidth / 2), this.DragOrigin.Y - (dragHeight / 2), dragWidth, dragHeight); // dragZone = new Rectangle(this.DragOrigin.X - (dragWidth / 2), this.DragOrigin.Y - (dragHeight / 2), dragWidth, dragHeight);
return !dragZone.Contains(location); // return !dragZone.Contains(location);
} // }
private void PositionDragHandles() // private void PositionDragHandles()
{ // {
if (this.DragHandles != null && this.DragHandleSize > 0) // if (this.DragHandles != null && this.DragHandleSize > 0)
{ // {
if (this.SelectionRegion.IsEmpty) // if (this.SelectionRegion.IsEmpty)
{ // {
foreach (DragHandle handle in this.DragHandles) // foreach (DragHandle handle in this.DragHandles)
{ // {
handle.Bounds = Rectangle.Empty; // handle.Bounds = Rectangle.Empty;
} // }
} // }
else // else
{ // {
int left; // int left;
int top; // int top;
int right; // int right;
int bottom; // int bottom;
int halfWidth; // int halfWidth;
int halfHeight; // int halfHeight;
int halfDragHandleSize; // int halfDragHandleSize;
Rectangle viewport; // Rectangle viewport;
int offsetX; // int offsetX;
int offsetY; // int offsetY;
viewport = this.GetImageViewPort(); // viewport = this.GetImageViewPort();
offsetX = viewport.Left + this.Padding.Left + this.AutoScrollPosition.X; // offsetX = viewport.Left + this.Padding.Left + this.AutoScrollPosition.X;
offsetY = viewport.Top + this.Padding.Top + this.AutoScrollPosition.Y; // offsetY = viewport.Top + this.Padding.Top + this.AutoScrollPosition.Y;
halfDragHandleSize = this.DragHandleSize / 2; // halfDragHandleSize = this.DragHandleSize / 2;
left = Convert.ToInt32((this.SelectionRegion.Left * this.ZoomFactor) + offsetX); // left = Convert.ToInt32((this.SelectionRegion.Left * this.ZoomFactor) + offsetX);
top = Convert.ToInt32((this.SelectionRegion.Top * this.ZoomFactor) + offsetY); // top = Convert.ToInt32((this.SelectionRegion.Top * this.ZoomFactor) + offsetY);
right = left + Convert.ToInt32(this.SelectionRegion.Width * this.ZoomFactor); // right = left + Convert.ToInt32(this.SelectionRegion.Width * this.ZoomFactor);
bottom = top + Convert.ToInt32(this.SelectionRegion.Height * this.ZoomFactor); // bottom = top + Convert.ToInt32(this.SelectionRegion.Height * this.ZoomFactor);
halfWidth = Convert.ToInt32(this.SelectionRegion.Width * this.ZoomFactor) / 2; // halfWidth = Convert.ToInt32(this.SelectionRegion.Width * this.ZoomFactor) / 2;
halfHeight = Convert.ToInt32(this.SelectionRegion.Height * this.ZoomFactor) / 2; // halfHeight = Convert.ToInt32(this.SelectionRegion.Height * this.ZoomFactor) / 2;
this.DragHandles[DragHandleAnchor.TopLeft].Bounds = new Rectangle(left - this.DragHandleSize, top - this.DragHandleSize, this.DragHandleSize, this.DragHandleSize); // this.DragHandles[DragHandleAnchor.TopLeft].Bounds = new Rectangle(left - this.DragHandleSize, top - this.DragHandleSize, this.DragHandleSize, this.DragHandleSize);
this.DragHandles[DragHandleAnchor.TopCenter].Bounds = new Rectangle(left + halfWidth - halfDragHandleSize, top - this.DragHandleSize, this.DragHandleSize, this.DragHandleSize); // this.DragHandles[DragHandleAnchor.TopCenter].Bounds = new Rectangle(left + halfWidth - halfDragHandleSize, top - this.DragHandleSize, this.DragHandleSize, this.DragHandleSize);
this.DragHandles[DragHandleAnchor.TopRight].Bounds = new Rectangle(right, top - this.DragHandleSize, this.DragHandleSize, this.DragHandleSize); // this.DragHandles[DragHandleAnchor.TopRight].Bounds = new Rectangle(right, top - this.DragHandleSize, this.DragHandleSize, this.DragHandleSize);
this.DragHandles[DragHandleAnchor.MiddleLeft].Bounds = new Rectangle(left - this.DragHandleSize, top + halfHeight - halfDragHandleSize, this.DragHandleSize, this.DragHandleSize); // this.DragHandles[DragHandleAnchor.MiddleLeft].Bounds = new Rectangle(left - this.DragHandleSize, top + halfHeight - halfDragHandleSize, this.DragHandleSize, this.DragHandleSize);
this.DragHandles[DragHandleAnchor.MiddleRight].Bounds = new Rectangle(right, top + halfHeight - halfDragHandleSize, this.DragHandleSize, this.DragHandleSize); // this.DragHandles[DragHandleAnchor.MiddleRight].Bounds = new Rectangle(right, top + halfHeight - halfDragHandleSize, this.DragHandleSize, this.DragHandleSize);
this.DragHandles[DragHandleAnchor.BottomLeft].Bounds = new Rectangle(left - this.DragHandleSize, bottom, this.DragHandleSize, this.DragHandleSize); // this.DragHandles[DragHandleAnchor.BottomLeft].Bounds = new Rectangle(left - this.DragHandleSize, bottom, this.DragHandleSize, this.DragHandleSize);
this.DragHandles[DragHandleAnchor.BottomCenter].Bounds = new Rectangle(left + halfWidth - halfDragHandleSize, bottom, this.DragHandleSize, this.DragHandleSize); // this.DragHandles[DragHandleAnchor.BottomCenter].Bounds = new Rectangle(left + halfWidth - halfDragHandleSize, bottom, this.DragHandleSize, this.DragHandleSize);
this.DragHandles[DragHandleAnchor.BottomRight].Bounds = new Rectangle(right, bottom, this.DragHandleSize, this.DragHandleSize); // this.DragHandles[DragHandleAnchor.BottomRight].Bounds = new Rectangle(right, bottom, this.DragHandleSize, this.DragHandleSize);
this.DragHandles[DragHandleAnchor.MiddleCenter].Bounds = new Rectangle(left + halfWidth - halfDragHandleSize, top + halfHeight - halfDragHandleSize, this.DragHandleSize, this.DragHandleSize); // this.DragHandles[DragHandleAnchor.MiddleCenter].Bounds = new Rectangle(left + halfWidth - halfDragHandleSize, top + halfHeight - halfDragHandleSize, this.DragHandleSize, this.DragHandleSize);
} // }
} // }
} // }
private void ProcessSelectionMove(Point cursorPosition) // private void ProcessSelectionMove(Point cursorPosition)
{ // {
if (this.IsMoving) // if (this.IsMoving)
{ // {
int x; // int x;
int y; // int y;
Point imagePoint; // Point imagePoint;
imagePoint = this.PointToImage(cursorPosition, true); // imagePoint = this.PointToImage(cursorPosition, true);
x = Math.Max(0, imagePoint.X - this.DragOriginOffset.X); // x = Math.Max(0, imagePoint.X - this.DragOriginOffset.X);
if (x + this.SelectionRegion.Width >= this.ViewSize.Width) // if (x + this.SelectionRegion.Width >= this.ViewSize.Width)
{ // {
x = this.ViewSize.Width - (int)this.SelectionRegion.Width; // x = this.ViewSize.Width - (int)this.SelectionRegion.Width;
} // }
y = Math.Max(0, imagePoint.Y - this.DragOriginOffset.Y); // y = Math.Max(0, imagePoint.Y - this.DragOriginOffset.Y);
if (y + this.SelectionRegion.Height >= this.ViewSize.Height) // if (y + this.SelectionRegion.Height >= this.ViewSize.Height)
{ // {
y = this.ViewSize.Height - (int)this.SelectionRegion.Height; // y = this.ViewSize.Height - (int)this.SelectionRegion.Height;
} // }
this.SelectionRegion = new RectangleF(x, y, this.SelectionRegion.Width, this.SelectionRegion.Height); // this.SelectionRegion = new RectangleF(x, y, this.SelectionRegion.Width, this.SelectionRegion.Height);
} // }
} // }
private void ProcessSelectionResize(Point cursorPosition) // private void ProcessSelectionResize(Point cursorPosition)
{ // {
if (this.IsResizing) // if (this.IsResizing)
{ // {
Point imagePosition; // Point imagePosition;
float left; // float left;
float top; // float top;
float right; // float right;
float bottom; // float bottom;
bool resizingTopEdge; // bool resizingTopEdge;
bool resizingBottomEdge; // bool resizingBottomEdge;
bool resizingLeftEdge; // bool resizingLeftEdge;
bool resizingRightEdge; // bool resizingRightEdge;
imagePosition = this.PointToImage(cursorPosition, true); // imagePosition = this.PointToImage(cursorPosition, true);
// get the current selection // // get the current selection
left = this.SelectionRegion.Left; // left = this.SelectionRegion.Left;
top = this.SelectionRegion.Top; // top = this.SelectionRegion.Top;
right = this.SelectionRegion.Right; // right = this.SelectionRegion.Right;
bottom = this.SelectionRegion.Bottom; // bottom = this.SelectionRegion.Bottom;
// decide which edges we're resizing // // decide which edges we're resizing
resizingTopEdge = this.ResizeAnchor >= DragHandleAnchor.TopLeft && this.ResizeAnchor <= DragHandleAnchor.TopRight; // resizingTopEdge = this.ResizeAnchor >= DragHandleAnchor.TopLeft && this.ResizeAnchor <= DragHandleAnchor.TopRight;
resizingBottomEdge = this.ResizeAnchor >= DragHandleAnchor.BottomLeft && this.ResizeAnchor <= DragHandleAnchor.BottomRight; // resizingBottomEdge = this.ResizeAnchor >= DragHandleAnchor.BottomLeft && this.ResizeAnchor <= DragHandleAnchor.BottomRight;
resizingLeftEdge = this.ResizeAnchor == DragHandleAnchor.TopLeft || this.ResizeAnchor == DragHandleAnchor.MiddleLeft || this.ResizeAnchor == DragHandleAnchor.BottomLeft; // resizingLeftEdge = this.ResizeAnchor == DragHandleAnchor.TopLeft || this.ResizeAnchor == DragHandleAnchor.MiddleLeft || this.ResizeAnchor == DragHandleAnchor.BottomLeft;
resizingRightEdge = this.ResizeAnchor == DragHandleAnchor.TopRight || this.ResizeAnchor == DragHandleAnchor.MiddleRight || this.ResizeAnchor == DragHandleAnchor.BottomRight; // resizingRightEdge = this.ResizeAnchor == DragHandleAnchor.TopRight || this.ResizeAnchor == DragHandleAnchor.MiddleRight || this.ResizeAnchor == DragHandleAnchor.BottomRight;
// and resize! // // and resize!
if (resizingTopEdge) // if (resizingTopEdge)
{ // {
top = imagePosition.Y; // top = imagePosition.Y;
if (bottom - top < this.MinimumSelectionSize.Height) // if (bottom - top < this.MinimumSelectionSize.Height)
{ // {
top = bottom - this.MinimumSelectionSize.Height; // top = bottom - this.MinimumSelectionSize.Height;
} // }
} // }
else if (resizingBottomEdge) // else if (resizingBottomEdge)
{ // {
bottom = imagePosition.Y; // bottom = imagePosition.Y;
if (bottom - top < this.MinimumSelectionSize.Height) // if (bottom - top < this.MinimumSelectionSize.Height)
{ // {
bottom = top + this.MinimumSelectionSize.Height; // bottom = top + this.MinimumSelectionSize.Height;
} // }
} // }
if (resizingLeftEdge) // if (resizingLeftEdge)
{ // {
left = imagePosition.X; // left = imagePosition.X;
if (right - left < this.MinimumSelectionSize.Width) // if (right - left < this.MinimumSelectionSize.Width)
{ // {
left = right - this.MinimumSelectionSize.Width; // left = right - this.MinimumSelectionSize.Width;
} // }
} // }
else if (resizingRightEdge) // else if (resizingRightEdge)
{ // {
right = imagePosition.X; // right = imagePosition.X;
if (right - left < this.MinimumSelectionSize.Width) // if (right - left < this.MinimumSelectionSize.Width)
{ // {
right = left + this.MinimumSelectionSize.Width; // right = left + this.MinimumSelectionSize.Width;
} // }
} // }
this.SelectionRegion = new RectangleF(left, top, right - left, bottom - top); // this.SelectionRegion = new RectangleF(left, top, right - left, bottom - top);
} // }
} // }
private void ResetDrag() // private void ResetDrag()
{ // {
this.IsResizing = false; // this.IsResizing = false;
this.IsMoving = false; // this.IsMoving = false;
this.DragOrigin = Point.Empty; // this.DragOrigin = Point.Empty;
this.DragOriginOffset = Point.Empty; // this.DragOriginOffset = Point.Empty;
} // }
private void SetCursor(Point point) // private void SetCursor(Point point)
{ // {
Cursor cursor; // Cursor cursor;
if (this.IsSelecting) // if (this.IsSelecting)
{ // {
cursor = Cursors.Default; // cursor = Cursors.Default;
} // }
else // else
{ // {
DragHandleAnchor handleAnchor; // DragHandleAnchor handleAnchor;
handleAnchor = this.IsResizing ? this.ResizeAnchor : this.HitTest(point); // handleAnchor = this.IsResizing ? this.ResizeAnchor : this.HitTest(point);
if (handleAnchor != DragHandleAnchor.None && this.DragHandles[handleAnchor].Enabled) // if (handleAnchor != DragHandleAnchor.None && this.DragHandles[handleAnchor].Enabled)
{ // {
switch (handleAnchor) // switch (handleAnchor)
{ // {
case DragHandleAnchor.TopLeft: // case DragHandleAnchor.TopLeft:
case DragHandleAnchor.BottomRight: // case DragHandleAnchor.BottomRight:
cursor = Cursors.SizeNWSE; // cursor = Cursors.SizeNWSE;
break; // break;
case DragHandleAnchor.TopCenter: // case DragHandleAnchor.TopCenter:
case DragHandleAnchor.BottomCenter: // case DragHandleAnchor.BottomCenter:
cursor = Cursors.SizeNS; // cursor = Cursors.SizeNS;
break; // break;
case DragHandleAnchor.TopRight: // case DragHandleAnchor.TopRight:
case DragHandleAnchor.BottomLeft: // case DragHandleAnchor.BottomLeft:
cursor = Cursors.SizeNESW; // cursor = Cursors.SizeNESW;
break; // break;
case DragHandleAnchor.MiddleLeft: // case DragHandleAnchor.MiddleLeft:
case DragHandleAnchor.MiddleRight: // case DragHandleAnchor.MiddleRight:
cursor = Cursors.SizeWE; // cursor = Cursors.SizeWE;
break; // break;
case DragHandleAnchor.MiddleCenter: // case DragHandleAnchor.MiddleCenter:
cursor = Cursors.Cross; // cursor = Cursors.Cross;
break; // break;
default: // default:
throw new ArgumentOutOfRangeException(); // throw new ArgumentOutOfRangeException();
} // }
} // }
else if (this.IsMoving || this.SelectionRegion.Contains(this.PointToImage(point))) // else if (this.IsMoving || this.SelectionRegion.Contains(this.PointToImage(point)))
{ // {
cursor = Cursors.SizeAll; // cursor = Cursors.SizeAll;
} // }
else // else
{ // {
cursor = Cursors.Default; // cursor = Cursors.Default;
} // }
} // }
this.Cursor = cursor; // this.Cursor = cursor;
} // }
private void StartResize(DragHandleAnchor anchor) // private void StartResize(DragHandleAnchor anchor)
{ // {
CancelEventArgs e; // CancelEventArgs e;
if (this.IsMoving || this.IsResizing) // if (this.IsMoving || this.IsResizing)
{ // {
throw new InvalidOperationException("A move or resize action is currently being performed."); // throw new InvalidOperationException("A move or resize action is currently being performed.");
} // }
e = new CancelEventArgs(); // e = new CancelEventArgs();
this.OnSelectionResizing(e); // this.OnSelectionResizing(e);
if (!e.Cancel) // if (!e.Cancel)
{ // {
this.ResizeAnchor = anchor; // this.ResizeAnchor = anchor;
this.PreviousSelectionRegion = this.SelectionRegion; // this.PreviousSelectionRegion = this.SelectionRegion;
this.IsResizing = true; // this.IsResizing = true;
} // }
} // }
#endregion // #endregion
} // }
} //}
...@@ -21,7 +21,8 @@ namespace Cyotek.Windows.Forms ...@@ -21,7 +21,8 @@ namespace Cyotek.Windows.Forms
[DefaultProperty("Image")] [DefaultProperty("Image")]
[ToolboxBitmap(typeof(ImageBox), "ImageBox.bmp")] [ToolboxBitmap(typeof(ImageBox), "ImageBox.bmp")]
[ToolboxItem(true)] [ToolboxItem(true)]
/* [Designer("Cyotek.Windows.Forms.Design.ImageBoxDesigner", Cyotek.Windows.Forms.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */ public class ImageBox : VirtualScrollableControl /* [Designer("Cyotek.Windows.Forms.Design.ImageBoxDesigner", Cyotek.Windows.Forms.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */
public class ImageBox : VirtualScrollableControl
{ {
#region Constants #region Constants
...@@ -83,7 +84,7 @@ namespace Cyotek.Windows.Forms ...@@ -83,7 +84,7 @@ namespace Cyotek.Windows.Forms
private ImageBoxSelectionMode _selectionMode; private ImageBoxSelectionMode _selectionMode;
private RectangleF _selectionRegion; private GraphicsPath _selectionRegion = new GraphicsPath();
private bool _shortcutsEnabled; private bool _shortcutsEnabled;
...@@ -892,8 +893,9 @@ namespace Cyotek.Windows.Forms ...@@ -892,8 +893,9 @@ namespace Cyotek.Windows.Forms
this.DrawPixelGrid(e.Graphics); this.DrawPixelGrid(e.Graphics);
} }
// draw the selection // draw the selection
if (this.SelectionRegion != Rectangle.Empty) if (this.SelectionRegion.PointCount > 0)
{ {
this.DrawSelection(e); this.DrawSelection(e);
} }
...@@ -1526,7 +1528,7 @@ namespace Cyotek.Windows.Forms ...@@ -1526,7 +1528,7 @@ namespace Cyotek.Windows.Forms
/// </value> /// </value>
[Browsable(false)] [Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual RectangleF SelectionRegion public virtual GraphicsPath SelectionRegion
{ {
get { return _selectionRegion; } get { return _selectionRegion; }
set set
...@@ -2378,20 +2380,26 @@ namespace Cyotek.Windows.Forms ...@@ -2378,20 +2380,26 @@ namespace Cyotek.Windows.Forms
result = null; result = null;
if (!this.SelectionRegion.IsEmpty) var bounds = this.SelectionRegion.GetBounds();
if (this.SelectionRegion.PointCount > 0)
{ {
Rectangle rect; if (bounds.Width > 0 && bounds.Height > 0)
rect = this.FitRectangle(new Rectangle((int)this.SelectionRegion.X, (int)this.SelectionRegion.Y, (int)this.SelectionRegion.Width, (int)this.SelectionRegion.Height));
if (rect.Width > 0 && rect.Height > 0)
{ {
result = new Bitmap(rect.Width, rect.Height); Bitmap mask = new Bitmap(this.Image.Width, this.Image.Height);
using (Graphics g = Graphics.FromImage(mask))
{
var br = new TextureBrush(this.Image);
g.FillPath(br, this.SelectionRegion);
}
var dstRect = new RectangleF(0, 0, bounds.Width, bounds.Height);
var srcRect = new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(result)) using (Graphics g = Graphics.FromImage(result))
{ {
g.DrawImage(this.Image, new Rectangle(Point.Empty, rect.Size), rect, GraphicsUnit.Pixel); result = new Bitmap((int)bounds.Width, (int)bounds.Width);
g.DrawImage(mask, dstRect, srcRect, GraphicsUnit.Pixel);
} }
return result;
} }
} }
...@@ -2629,20 +2637,11 @@ namespace Cyotek.Windows.Forms ...@@ -2629,20 +2637,11 @@ namespace Cyotek.Windows.Forms
} }
/// <summary> /// <summary>
/// Creates a selection region which encompasses the entire image
/// </summary>
/// <exception cref="System.InvalidOperationException">Thrown if no image is currently set</exception>
public virtual void SelectAll()
{
this.SelectionRegion = new RectangleF(PointF.Empty, this.ViewSize);
}
/// <summary>
/// Clears any existing selection region /// Clears any existing selection region
/// </summary> /// </summary>
public virtual void SelectNone() public virtual void SelectNone()
{ {
this.SelectionRegion = RectangleF.Empty; this.SelectionRegion = new GraphicsPath();
} }
/// <summary> /// <summary>
...@@ -3160,20 +3159,36 @@ namespace Cyotek.Windows.Forms ...@@ -3160,20 +3159,36 @@ namespace Cyotek.Windows.Forms
/// </param> /// </param>
protected virtual void DrawSelection(PaintEventArgs e) protected virtual void DrawSelection(PaintEventArgs e)
{ {
RectangleF rect;
e.Graphics.SetClip(this.GetInsideViewPort(true)); e.Graphics.SetClip(this.GetInsideViewPort(true));
rect = this.GetOffsetRectangle(this.SelectionRegion); GraphicsPath newPath = new GraphicsPath(this.SelectionRegion.PathPoints, this.SelectionRegion.PathTypes);
Matrix matrix = new Matrix();
matrix.Scale((float)this.ZoomFactor, (float)this.ZoomFactor);
newPath.Transform(matrix);
var viewport = this.GetImageViewPort();
var offsetX = viewport.Left + this.Padding.Left + this.AutoScrollPosition.X;
var offsetY = viewport.Top + this.Padding.Top + this.AutoScrollPosition.Y;
matrix = new Matrix();
matrix.Translate(offsetX, offsetY);
newPath.Transform(matrix);
//rect = this.GetOffsetRectangle(this.SelectionRegion);
using (Brush brush = new SolidBrush(Color.FromArgb(128, this.SelectionColor))) using (Brush brush = new SolidBrush(Color.FromArgb(128, this.SelectionColor)))
{ {
e.Graphics.FillRectangle(brush, rect); e.Graphics.FillPath(brush, newPath);
} }
using (Pen pen = new Pen(this.SelectionColor)) using (Pen pen = new Pen(this.SelectionColor))
{ {
e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); //e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
e.Graphics.DrawPath(pen, newPath);
} }
e.Graphics.ResetClip(); e.Graphics.ResetClip();
...@@ -3670,16 +3685,16 @@ namespace Cyotek.Windows.Forms ...@@ -3670,16 +3685,16 @@ namespace Cyotek.Windows.Forms
{ {
EventHandler<EventArgs> handler; EventHandler<EventArgs> handler;
switch (this.SelectionMode) //switch (this.SelectionMode)
{ //{
case ImageBoxSelectionMode.Zoom: // case ImageBoxSelectionMode.Zoom:
if (this.SelectionRegion.Width > SelectionDeadZone && this.SelectionRegion.Height > SelectionDeadZone) // if (this.SelectionRegion.Width > SelectionDeadZone && this.SelectionRegion.Height > SelectionDeadZone)
{ // {
this.ZoomToRegion(this.SelectionRegion); // this.ZoomToRegion(this.SelectionRegion);
this.SelectNone(); // this.SelectNone();
} // }
break; // break;
} //}
handler = this.Selected; handler = this.Selected;
...@@ -4205,8 +4220,10 @@ namespace Cyotek.Windows.Forms ...@@ -4205,8 +4220,10 @@ namespace Cyotek.Windows.Forms
{ {
selection = this.FitRectangle(selection); selection = this.FitRectangle(selection);
} }
GraphicsPath path = new GraphicsPath();
this.SelectionRegion = selection; Region re = new Region();
path.AddRectangle(selection);
this.SelectionRegion = path;
} }
} }
} }
......
...@@ -27,6 +27,6 @@ ...@@ -27,6 +27,6 @@
/// <summary> /// <summary>
/// Zoom selection. /// Zoom selection.
/// </summary> /// </summary>
Zoom Eclipse,
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!