Commit 860cabb5 SK

保存项目

1 个父辈 5245bd9e
...@@ -12,11 +12,26 @@ namespace AOI ...@@ -12,11 +12,26 @@ namespace AOI
{ {
public abstract class AoiMethod public abstract class AoiMethod
{ {
//public string FullTypeName { get; set; }
//public string PathDatas { get; set; }
public string MethodName { get; set; } public string MethodName { get; set; }
/// <summary> /// <summary>
/// 兴趣区域路径 /// 兴趣区域路径
/// </summary> /// </summary>
public GraphicsPath RoiPath; [Newtonsoft.Json.JsonIgnore()]
public GraphicsPath RoiPath { get; set; }
public PathData GetRoiPathData()
{
if (RoiPath != null)
{
return RoiPath.PathData;
}
return null;
}
public abstract ResultBean Check(Image standardImage, Image imageToCheck); public abstract ResultBean Check(Image standardImage, Image imageToCheck);
......
...@@ -22,7 +22,7 @@ namespace AOI ...@@ -22,7 +22,7 @@ namespace AOI
/// <summary> /// <summary>
/// 标准的Image /// 标准的Image
/// </summary> /// </summary>
private Image standardImage { get; set; } public Image standardImage { get; set; }
/// <summary> /// <summary>
/// 所有的AOI方法 /// 所有的AOI方法
...@@ -68,7 +68,18 @@ namespace AOI ...@@ -68,7 +68,18 @@ namespace AOI
Dictionary<string, string> projectMap = new Dictionary<string, string>(); Dictionary<string, string> projectMap = new Dictionary<string, string>();
string base64ImgStr = Base64Util.ToBase64(this.standardImage); string base64ImgStr = Base64Util.ToBase64(this.standardImage);
projectMap.Add("base64Img", base64ImgStr); projectMap.Add("base64Img", base64ImgStr);
string methodMapJson = JsonUtil.SerializeObject(this.methodMap); var mapForJson = new Dictionary<string, string>();
foreach(var item in this.methodMap)
{
JObject obj = JObject.FromObject(item.Value);
obj.Add("FullTypeName",item.Value.GetType().FullName);
var roiPathData = item.Value.GetRoiPathData();
string roiPathDataStr = JsonUtil.SerializeObject(roiPathData);
obj.Add("PathDataStr", roiPathDataStr);
string jsonStr = JsonUtil.SerializeObject(obj);
mapForJson.Add(item.Key, jsonStr);
}
string methodMapJson = JsonUtil.SerializeObject(mapForJson);
projectMap.Add("methodMap", methodMapJson); projectMap.Add("methodMap", methodMapJson);
JsonUtil.SerializeObjectToFile(projectMap,filePath,false); JsonUtil.SerializeObjectToFile(projectMap,filePath,false);
} }
...@@ -79,7 +90,21 @@ namespace AOI ...@@ -79,7 +90,21 @@ namespace AOI
string base64Img = projectMap["base64Img"]; string base64Img = projectMap["base64Img"];
this.standardImage = Base64Util.ToImage(base64Img); this.standardImage = Base64Util.ToImage(base64Img);
string methodMapJson = projectMap["methodMap"]; string methodMapJson = projectMap["methodMap"];
this.methodMap = JsonUtil.DeserializeJsonToObject<Dictionary<string, AoiMethod>>(methodMapJson); var jsonMap = JsonUtil.DeserializeJsonToObject<Dictionary<string, string>>(methodMapJson);
foreach(var item in jsonMap)
{
JObject obj = JObject.Parse(item.Value);
string fullTypeName = obj.Value<string>("FullTypeName");
Type t = Type.GetType(fullTypeName);
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(item.Value);
object o = serializer.Deserialize(new JsonTextReader(sr), t);
AoiMethod aoiMethod = (AoiMethod)o;
string PathDataStr = obj.Value<string>("PathDataStr");
PathData pathData = JsonUtil.DeserializeJsonToObject<PathData>(PathDataStr);
aoiMethod.RoiPath = new GraphicsPath(pathData.Points, pathData.Types);
methodMap.Add(item.Key, aoiMethod);
}
} }
......
...@@ -13,20 +13,20 @@ namespace AOI ...@@ -13,20 +13,20 @@ namespace AOI
/// </summary> /// </summary>
public class AoiMethodRgb : AoiMethod public class AoiMethodRgb : AoiMethod
{ {
public int minR = 1; public int minR { get; set; }
public int maxR = 255; public int maxR { get; set; }
public int minG = 1; public int minG { get; set; }
public int maxG = 255; public int maxG { get; set; }
public int minB = 1; public int minB { get; set; }
public int maxB = 255; public int maxB { get; set; }
/// <summary> /// <summary>
/// 抽取出的像素最小占比 /// 抽取出的像素最小占比
/// </summary> /// </summary>
public float minRate = 0; public float minRate { get; set; }
/// <summary> /// <summary>
/// 抽取出的像素最大占比 /// 抽取出的像素最大占比
/// </summary> /// </summary>
public float maxRate = 100; public float maxRate { get; set; }
public override ResultBean Check(Image standardImage, Image imageToCheck) public override ResultBean Check(Image standardImage, Image imageToCheck)
{ {
......
...@@ -66,6 +66,7 @@ namespace AOI ...@@ -66,6 +66,7 @@ namespace AOI
T t = o as T; T t = o as T;
return t; return t;
} }
/// <summary> /// <summary>
/// 解析文件到生成对象实体 /// 解析文件到生成对象实体
/// </summary> /// </summary>
......
...@@ -49,25 +49,25 @@ ...@@ -49,25 +49,25 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="control\AioMarkControl.cs"> <Compile Include="control\AioMarkControl.cs">
<SubType>UserControl</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="control\AioMarkControl.Designer.cs"> <Compile Include="control\AioMarkControl.Designer.cs">
<DependentUpon>AioMarkControl.cs</DependentUpon> <DependentUpon>AioMarkControl.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="control\AoiBlobControl.cs"> <Compile Include="control\AoiBlobControl.cs">
<SubType>UserControl</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="control\AoiBlobControl.Designer.cs"> <Compile Include="control\AoiBlobControl.Designer.cs">
<DependentUpon>AoiBlobControl.cs</DependentUpon> <DependentUpon>AoiBlobControl.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="control\ABaseControl.cs"> <Compile Include="control\ABaseControl.cs">
<SubType>UserControl</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="control\ABaseControl.Designer.cs"> <Compile Include="control\ABaseControl.Designer.cs">
<DependentUpon>ABaseControl.cs</DependentUpon> <DependentUpon>ABaseControl.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="control\AoiRgbControl.cs"> <Compile Include="control\AoiRgbControl.cs">
<SubType>UserControl</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="control\AoiRgbControl.Designer.cs"> <Compile Include="control\AoiRgbControl.Designer.cs">
<DependentUpon>AoiRgbControl.cs</DependentUpon> <DependentUpon>AoiRgbControl.cs</DependentUpon>
...@@ -88,9 +88,7 @@ ...@@ -88,9 +88,7 @@
<Compile Include="imageBoxEx\DragHandle.cs" /> <Compile Include="imageBoxEx\DragHandle.cs" />
<Compile Include="imageBoxEx\DragHandleAnchor.cs" /> <Compile Include="imageBoxEx\DragHandleAnchor.cs" />
<Compile Include="imageBoxEx\DragHandleCollection.cs" /> <Compile Include="imageBoxEx\DragHandleCollection.cs" />
<Compile Include="imageBoxEx\ImageBoxEx.cs"> <Compile Include="imageBoxEx\ImageBoxEx.cs" />
<SubType>Component</SubType>
</Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="control\AioMarkControl.resx"> <EmbeddedResource Include="control\AioMarkControl.resx">
......
namespace AccAOI using Cyotek.Windows.Forms;
namespace AccAOI
{ {
partial class Form1 partial class Form1
{ {
...@@ -40,8 +42,8 @@ ...@@ -40,8 +42,8 @@
this.minB = new System.Windows.Forms.NumericUpDown(); this.minB = new System.Windows.Forms.NumericUpDown();
this.maxB = new System.Windows.Forms.NumericUpDown(); this.maxB = new System.Windows.Forms.NumericUpDown();
this.labelCount = new System.Windows.Forms.Label(); this.labelCount = new System.Windows.Forms.Label();
this.imageBoxEx1 = new AccAOI.ImageBoxEx(); this.imageBoxEx1 = new ImageBox();
this.imageBox = new AccAOI.ImageBoxEx(); this.imageBox = new ImageBox();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.maxR)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.maxR)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.minR)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.minR)).BeginInit();
...@@ -203,7 +205,7 @@ ...@@ -203,7 +205,7 @@
// //
// imageBoxEx1 // imageBoxEx1
// //
this.imageBoxEx1.DragHandleSize = 9; //this.imageBoxEx1.DragHandleSize = 9;
this.imageBoxEx1.Location = new System.Drawing.Point(475, 50); this.imageBoxEx1.Location = new System.Drawing.Point(475, 50);
this.imageBoxEx1.Name = "imageBoxEx1"; this.imageBoxEx1.Name = "imageBoxEx1";
this.imageBoxEx1.Size = new System.Drawing.Size(230, 159); this.imageBoxEx1.Size = new System.Drawing.Size(230, 159);
...@@ -212,7 +214,7 @@ ...@@ -212,7 +214,7 @@
// imageBox // imageBox
// //
this.imageBox.Dock = System.Windows.Forms.DockStyle.Fill; this.imageBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.imageBox.DragHandleSize = 9; //this.imageBox.DragHandleSize = 9;
this.imageBox.Location = new System.Drawing.Point(0, 0); this.imageBox.Location = new System.Drawing.Point(0, 0);
this.imageBox.Name = "imageBox"; this.imageBox.Name = "imageBox";
this.imageBox.SelectionColor = System.Drawing.Color.Empty; this.imageBox.SelectionColor = System.Drawing.Color.Empty;
...@@ -258,7 +260,7 @@ ...@@ -258,7 +260,7 @@
#endregion #endregion
private System.Windows.Forms.Button buttonOpen; private System.Windows.Forms.Button buttonOpen;
private ImageBoxEx imageBox; private ImageBox imageBox;
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label R; private System.Windows.Forms.Label R;
private System.Windows.Forms.NumericUpDown maxR; private System.Windows.Forms.NumericUpDown maxR;
...@@ -269,7 +271,7 @@ ...@@ -269,7 +271,7 @@
private System.Windows.Forms.NumericUpDown maxG; private System.Windows.Forms.NumericUpDown maxG;
private System.Windows.Forms.NumericUpDown minB; private System.Windows.Forms.NumericUpDown minB;
private System.Windows.Forms.NumericUpDown maxB; private System.Windows.Forms.NumericUpDown maxB;
private ImageBoxEx imageBoxEx1; private ImageBox imageBoxEx1;
private System.Windows.Forms.Label labelCount; private System.Windows.Forms.Label labelCount;
} }
} }
......
...@@ -63,11 +63,8 @@ namespace AccAOI ...@@ -63,11 +63,8 @@ namespace AccAOI
//{ //{
Matrix translateMatrix = new Matrix(); Matrix translateMatrix = new Matrix();
translateMatrix.Translate(100, 0); translateMatrix.Translate(100, 0);
RectangleF region = imageBox.SelectionRegion; Image threshImage = CutImage(imageBox.Image, imageBox.SelectionRegion);
GraphicsPath path = new GraphicsPath();
path.AddEllipse(region);
Image threshImage = CutImage(imageBox.Image, path);
cutImage = threshImage; cutImage = threshImage;
imageBoxEx1.Image = threshImage; imageBoxEx1.Image = threshImage;
} }
......
namespace AccAOI using Cyotek.Windows.Forms;
namespace AccAOI
{ {
partial class FrmAoiSetting partial class FrmAoiSetting
{ {
...@@ -38,7 +40,7 @@ ...@@ -38,7 +40,7 @@
this.btnGetCameraImg = new Asa.Theme.FlatButton(); this.btnGetCameraImg = new Asa.Theme.FlatButton();
this.comType = new Asa.Theme.FlatCombo(); this.comType = new Asa.Theme.FlatCombo();
this.panAoi = new System.Windows.Forms.Panel(); this.panAoi = new System.Windows.Forms.Panel();
this.imageBox1 = new AccAOI.ImageBoxEx(); this.imageBox1 = new ImageBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// aoiList // aoiList
...@@ -158,7 +160,7 @@ ...@@ -158,7 +160,7 @@
this.imageBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.imageBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.imageBox1.DragHandleSize = 9; //this.imageBox1.DragHandleSize = 9;
this.imageBox1.Location = new System.Drawing.Point(625, 40); this.imageBox1.Location = new System.Drawing.Point(625, 40);
this.imageBox1.Name = "imageBox1"; this.imageBox1.Name = "imageBox1";
this.imageBox1.SelectionMode = Cyotek.Windows.Forms.ImageBoxSelectionMode.Rectangle; this.imageBox1.SelectionMode = Cyotek.Windows.Forms.ImageBoxSelectionMode.Rectangle;
...@@ -204,7 +206,7 @@ ...@@ -204,7 +206,7 @@
#endregion #endregion
private Asa.Theme.FlatList aoiList; private Asa.Theme.FlatList aoiList;
private ImageBoxEx imageBox1; private ImageBox imageBox1;
private Asa.Theme.FlatButton btnOpenPro; private Asa.Theme.FlatButton btnOpenPro;
private Asa.Theme.FlatButton btnSavePro; private Asa.Theme.FlatButton btnSavePro;
private Asa.Theme.FlatButton btnNewAoi; private Asa.Theme.FlatButton btnNewAoi;
......
...@@ -73,11 +73,6 @@ namespace AccAOI ...@@ -73,11 +73,6 @@ namespace AccAOI
private void btnOpenPro_Click(object sender, EventArgs e) private void btnOpenPro_Click(object sender, EventArgs e)
{ {
if (this.Img == null)
{
MessageBox.Show("清先打开图片");
return;
}
System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog(); System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog();
openDialog.Title = "打开项目"; openDialog.Title = "打开项目";
openDialog.Filter = "(*.data)|*.data|(*.*)|*.*"; openDialog.Filter = "(*.data)|*.data|(*.*)|*.*";
...@@ -188,7 +183,7 @@ namespace AccAOI ...@@ -188,7 +183,7 @@ namespace AccAOI
if (method.RoiPath != null) if (method.RoiPath != null)
{ {
currPath = method.RoiPath; currPath = method.RoiPath;
imageBox1.SelectionRegion = method.RoiPath.GetBounds(); imageBox1.SelectionRegion = method.RoiPath;
Image threshImage = CutImage(imageBox1.Image, currPath); Image threshImage = CutImage(imageBox1.Image, currPath);
cutImage = threshImage; cutImage = threshImage;
...@@ -227,6 +222,8 @@ namespace AccAOI ...@@ -227,6 +222,8 @@ namespace AccAOI
if (Project != null) if (Project != null)
{ {
aoiList.ItemClear(); aoiList.ItemClear();
imageBox1.Image = Project.standardImage;
imageBox1.SelectionRegion = new GraphicsPath();
if (Project.methodMap.Count > 0) if (Project.methodMap.Count > 0)
{ {
foreach(string key in Project.methodMap.Keys) foreach(string key in Project.methodMap.Keys)
...@@ -273,16 +270,17 @@ namespace AccAOI ...@@ -273,16 +270,17 @@ namespace AccAOI
Matrix translateMatrix = new Matrix(); Matrix translateMatrix = new Matrix();
translateMatrix.Translate(100, 0); translateMatrix.Translate(100, 0);
RectangleF region = imageBox1.SelectionRegion; //RectangleF region = imageBox1.SelectionRegion;
currPath = new GraphicsPath(); //currPath = new GraphicsPath();
if (aoiControl.AreaType.Equals(1)) //if (aoiControl.AreaType.Equals(1))
{ //{
currPath.AddRectangle(region); // currPath.AddRectangle(region);
} //}
else //else
{ //{
currPath.AddEllipse(region); // currPath.AddEllipse(region);
} //}
currPath = imageBox1.SelectionRegion;
Image threshImage = CutImage(imageBox1.Image, currPath); Image threshImage = CutImage(imageBox1.Image, currPath);
cutImage = threshImage; cutImage = threshImage;
......
namespace AccAOI.control using Cyotek.Windows.Forms;
namespace AccAOI.control
{ {
partial class ABaseControl partial class ABaseControl
{ {
...@@ -36,7 +38,7 @@ ...@@ -36,7 +38,7 @@
this.btnClearArea = new Asa.Theme.FlatButton(); this.btnClearArea = new Asa.Theme.FlatButton();
this.btnSetArea = new Asa.Theme.FlatButton(); this.btnSetArea = new Asa.Theme.FlatButton();
this.btnYuan = new Asa.Theme.FlatButton(); this.btnYuan = new Asa.Theme.FlatButton();
this.aoiImage = new AccAOI.ImageBoxEx(); this.aoiImage = new ImageBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// panControl // panControl
...@@ -136,7 +138,7 @@ ...@@ -136,7 +138,7 @@
// //
this.aoiImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.aoiImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.aoiImage.DragHandleSize = 9; //this.aoiImage.DragHandleSize = 9;
this.aoiImage.Location = new System.Drawing.Point(9, 53); this.aoiImage.Location = new System.Drawing.Point(9, 53);
this.aoiImage.Name = "aoiImage"; this.aoiImage.Name = "aoiImage";
this.aoiImage.Size = new System.Drawing.Size(288, 182); this.aoiImage.Size = new System.Drawing.Size(288, 182);
...@@ -171,7 +173,7 @@ ...@@ -171,7 +173,7 @@
private Asa.Theme.FlatPanel panControl; private Asa.Theme.FlatPanel panControl;
protected Asa.Theme.FlatPanel panParam; protected Asa.Theme.FlatPanel panParam;
protected Asa.Theme.FlatPanel panResult; protected Asa.Theme.FlatPanel panResult;
public ImageBoxEx aoiImage; public ImageBox aoiImage;
private Asa.Theme.FlatButton btnYuan; private Asa.Theme.FlatButton btnYuan;
} }
} }
...@@ -32,11 +32,11 @@ namespace AccAOI.control ...@@ -32,11 +32,11 @@ namespace AccAOI.control
/// 区域信息 /// 区域信息
/// </summary> /// </summary>
public GraphicsPath currPath = null; public GraphicsPath currPath = null;
internal ImageBoxEx BImageBox; internal ImageBox BImageBox;
internal AoiMethod AoiInfo; internal AoiMethod AoiInfo;
public void SetImageBox(ImageBoxEx box) public void SetImageBox(ImageBox box)
{ {
this.BImageBox = box; this.BImageBox = box;
} }
...@@ -67,7 +67,7 @@ namespace AccAOI.control ...@@ -67,7 +67,7 @@ namespace AccAOI.control
private void btnClearArea_Click(object sender, EventArgs e) private void btnClearArea_Click(object sender, EventArgs e)
{ {
this.BImageBox.CleearArea(); //this.BImageBox.CleearArea();
this.aoiImage.Image = null; this.aoiImage.Image = null;
} }
......
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.
public class ImageBoxEx : ImageBox // public class ImageBoxEx : ImageBox
{ // {
public void CleearArea() // public void CleearArea()
{ // {
} // }
#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
} // }
} //}
...@@ -895,7 +895,7 @@ namespace Cyotek.Windows.Forms ...@@ -895,7 +895,7 @@ namespace Cyotek.Windows.Forms
// draw the selection // draw the selection
if (this.SelectionRegion.PointCount > 0) if (this.SelectionRegion != null && this.SelectionRegion.PointCount > 0)
{ {
this.DrawSelection(e); this.DrawSelection(e);
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!