Commit ee59400f SK

可编辑矩形和圆形

1 个父辈 1c38d4d4
正在显示 30 个修改的文件 包含 875 行增加1619 行删除
......@@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.27703.2035
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccAOI", "AccAOI\AccAOI.csproj", "{81D116DC-69C9-4B3B-AB7B-E324AF18CA3E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageBox", "ImageBox\ImageBox.csproj", "{DB03ED04-5E06-4FEB-B891-0633448F24EC}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccImageBox", "ImageBox\AccImageBox.csproj", "{DB03ED04-5E06-4FEB-B891-0633448F24EC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOI", "AOI\AOI.csproj", "{529F3829-BD91-42A7-95AF-9DEA2DC409CB}"
EndProject
......
......@@ -87,12 +87,6 @@
<Compile Include="control\AoiRgbControl.Designer.cs">
<DependentUpon>AoiRgbControl.cs</DependentUpon>
</Compile>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="FrmAoiSetting.cs">
<SubType>Form</SubType>
</Compile>
......@@ -100,10 +94,6 @@
<DependentUpon>FrmAoiSetting.cs</DependentUpon>
</Compile>
<Compile Include="FormUtil.cs" />
<Compile Include="imageBoxEx\DragHandle.cs" />
<Compile Include="imageBoxEx\DragHandleAnchor.cs" />
<Compile Include="imageBoxEx\DragHandleCollection.cs" />
<Compile Include="imageBoxEx\ImageBoxEx.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="control\AioMarkControl.resx">
......@@ -118,9 +108,6 @@
<EmbeddedResource Include="control\AoiRgbControl.resx">
<DependentUpon>AoiRgbControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmAoiSetting.resx">
<DependentUpon>FrmAoiSetting.cs</DependentUpon>
</EmbeddedResource>
......@@ -152,9 +139,9 @@
<Project>{529f3829-bd91-42a7-95af-9dea2dc409cb}</Project>
<Name>AOI</Name>
</ProjectReference>
<ProjectReference Include="..\ImageBox\ImageBox.csproj">
<ProjectReference Include="..\ImageBox\AccImageBox.csproj">
<Project>{db03ed04-5e06-4feb-b891-0633448f24ec}</Project>
<Name>ImageBox</Name>
<Name>AccImageBox</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
......
using Cyotek.Windows.Forms;
namespace AccAOI
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.buttonOpen = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.R = new System.Windows.Forms.Label();
this.maxR = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.minR = new System.Windows.Forms.NumericUpDown();
this.minG = new System.Windows.Forms.NumericUpDown();
this.maxG = new System.Windows.Forms.NumericUpDown();
this.minB = new System.Windows.Forms.NumericUpDown();
this.maxB = new System.Windows.Forms.NumericUpDown();
this.labelCount = new System.Windows.Forms.Label();
this.imageBoxEx1 = new ImageBox();
this.imageBox = new ImageBox();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.maxR)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.minR)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.minG)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.maxG)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.minB)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.maxB)).BeginInit();
this.SuspendLayout();
//
// buttonOpen
//
this.buttonOpen.Location = new System.Drawing.Point(12, 12);
this.buttonOpen.Name = "buttonOpen";
this.buttonOpen.Size = new System.Drawing.Size(75, 23);
this.buttonOpen.TabIndex = 1;
this.buttonOpen.Text = "打开";
this.buttonOpen.UseVisualStyleBackColor = true;
this.buttonOpen.Click += new System.EventHandler(this.buttonOpen_Click);
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.Controls.Add(this.imageBox);
this.panel1.Location = new System.Drawing.Point(12, 50);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(457, 388);
this.panel1.TabIndex = 3;
//
// R
//
this.R.AutoSize = true;
this.R.Location = new System.Drawing.Point(503, 219);
this.R.Name = "R";
this.R.Size = new System.Drawing.Size(11, 12);
this.R.TabIndex = 7;
this.R.Text = "R";
//
// maxR
//
this.maxR.Location = new System.Drawing.Point(614, 215);
this.maxR.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.maxR.Name = "maxR";
this.maxR.Size = new System.Drawing.Size(52, 21);
this.maxR.TabIndex = 9;
this.maxR.Value = new decimal(new int[] {
255,
0,
0,
0});
this.maxR.ValueChanged += new System.EventHandler(this.maxR_ValueChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(503, 267);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(11, 12);
this.label1.TabIndex = 10;
this.label1.Text = "G";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(503, 313);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(11, 12);
this.label2.TabIndex = 13;
this.label2.Text = "B";
//
// minR
//
this.minR.Location = new System.Drawing.Point(529, 215);
this.minR.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.minR.Name = "minR";
this.minR.Size = new System.Drawing.Size(52, 21);
this.minR.TabIndex = 16;
this.minR.ValueChanged += new System.EventHandler(this.minR_ValueChanged);
//
// minG
//
this.minG.Location = new System.Drawing.Point(529, 265);
this.minG.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.minG.Name = "minG";
this.minG.Size = new System.Drawing.Size(52, 21);
this.minG.TabIndex = 18;
this.minG.ValueChanged += new System.EventHandler(this.minG_ValueChanged);
//
// maxG
//
this.maxG.Location = new System.Drawing.Point(614, 265);
this.maxG.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.maxG.Name = "maxG";
this.maxG.Size = new System.Drawing.Size(52, 21);
this.maxG.TabIndex = 17;
this.maxG.Value = new decimal(new int[] {
255,
0,
0,
0});
this.maxG.ValueChanged += new System.EventHandler(this.maxG_ValueChanged);
//
// minB
//
this.minB.Location = new System.Drawing.Point(529, 311);
this.minB.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.minB.Name = "minB";
this.minB.Size = new System.Drawing.Size(52, 21);
this.minB.TabIndex = 20;
this.minB.ValueChanged += new System.EventHandler(this.minB_ValueChanged);
//
// maxB
//
this.maxB.Location = new System.Drawing.Point(614, 311);
this.maxB.Maximum = new decimal(new int[] {
255,
0,
0,
0});
this.maxB.Name = "maxB";
this.maxB.Size = new System.Drawing.Size(52, 21);
this.maxB.TabIndex = 19;
this.maxB.Value = new decimal(new int[] {
255,
0,
0,
0});
this.maxB.ValueChanged += new System.EventHandler(this.maxB_ValueChanged);
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(540, 376);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(11, 12);
this.labelCount.TabIndex = 22;
this.labelCount.Text = "0";
//
// imageBoxEx1
//
//this.imageBoxEx1.DragHandleSize = 9;
this.imageBoxEx1.Location = new System.Drawing.Point(475, 50);
this.imageBoxEx1.Name = "imageBoxEx1";
this.imageBoxEx1.Size = new System.Drawing.Size(230, 159);
this.imageBoxEx1.TabIndex = 21;
//
// imageBox
//
this.imageBox.Dock = System.Windows.Forms.DockStyle.Fill;
//this.imageBox.DragHandleSize = 9;
this.imageBox.Location = new System.Drawing.Point(0, 0);
this.imageBox.Name = "imageBox";
this.imageBox.SelectionColor = System.Drawing.Color.Empty;
this.imageBox.SelectionMode = Cyotek.Windows.Forms.ImageBoxSelectionMode.Rectangle;
this.imageBox.ShowPixelGrid = true;
this.imageBox.Size = new System.Drawing.Size(457, 388);
this.imageBox.TabIndex = 2;
this.imageBox.Text = "imageBoxEx1";
this.imageBox.Selected += new System.EventHandler<System.EventArgs>(this.imageBox_Selected);
this.imageBox.SelectionRegionChanged += new System.EventHandler(this.imageBox_SelectionRegionChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(717, 450);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.imageBoxEx1);
this.Controls.Add(this.minB);
this.Controls.Add(this.maxB);
this.Controls.Add(this.minG);
this.Controls.Add(this.maxG);
this.Controls.Add(this.minR);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.maxR);
this.Controls.Add(this.R);
this.Controls.Add(this.panel1);
this.Controls.Add(this.buttonOpen);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.maxR)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.minR)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.minG)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.maxG)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.minB)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.maxB)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonOpen;
private ImageBox imageBox;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label R;
private System.Windows.Forms.NumericUpDown maxR;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown minR;
private System.Windows.Forms.NumericUpDown minG;
private System.Windows.Forms.NumericUpDown maxG;
private System.Windows.Forms.NumericUpDown minB;
private System.Windows.Forms.NumericUpDown maxB;
private ImageBox imageBoxEx1;
private System.Windows.Forms.Label labelCount;
}
}
using Cyotek.Windows.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AccAOI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Image originalImage;
private void buttonOpen_Click(object sender, EventArgs e)
{
using (FileDialog dialog = new OpenFileDialog())
{
dialog.Filter = "All Supported Images (*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png)|*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png|Bitmaps (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|Graphics Interchange Format (*.gif)|*.gif|Joint Photographic Experts (*.jpg)|*.jpg|Portable Network Graphics (*.png)|*.png|All Files (*.*)|*.*";
dialog.DefaultExt = "png";
if (dialog.ShowDialog(this) == DialogResult.OK)
{
try
{
originalImage = Image.FromFile(dialog.FileName);
imageBox.Image = originalImage;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void imageBox_Selected(object sender, EventArgs e)
{
//Image selectImage = imageBox.GetSelectedImage();
//RectangleF region = imageBox.SelectionRegion;
//Image threshImage = ImageUtil.Merge(originalImage, selectImage, region);
//imageBox.Image = threshImage;
}
private void imageBox_SelectionRegionChanged(object sender, EventArgs e)
{
//Image selectImage = imageBox.GetSelectedImage();
//if (selectImage != null)
//{
Matrix translateMatrix = new Matrix();
translateMatrix.Translate(100, 0);
Image threshImage = CutImage(imageBox.Image, imageBox.SelectionRegion);
cutImage = threshImage;
imageBoxEx1.Image = threshImage;
}
private Image CutImage(Image src, GraphicsPath path)
{
var bounds = path.GetBounds();
Bitmap b = new Bitmap(src.Width, src.Height);
using (Graphics g = Graphics.FromImage(b))
{
var br = new TextureBrush(src);
g.FillPath(br, path);
}
if(bounds.Width > 0 && bounds.Height > 0)
{
Bitmap result = new Bitmap((int)bounds.Width, (int)bounds.Height);
var srcRect = bounds;
var dstRect = new RectangleF(0, 0, bounds.Width, bounds.Height);
bounds.Location = System.Drawing.Point.Empty;
using (Graphics g = Graphics.FromImage(result))
{
bounds.Location = System.Drawing.Point.Empty;
g.DrawImage(b, dstRect, srcRect, GraphicsUnit.Pixel);
}
return result;
}
return null;
}
Image cutImage;
private void InRangeImage()
{
//Mat src = BitmapConverter.ToMat(new Bitmap(cutImage));
//Cv2.CvtColor(src, src, ColorConversionCodes.BGRA2BGR);
//Mat dst = new Mat();
//Scalar minScalar = Scalar.FromRgb((int)minR.Value, (int)minG.Value, (int)minB.Value);
//Scalar maxScalar = Scalar.FromRgb((int)maxR.Value, (int)maxG.Value, (int)maxB.Value);
//Cv2.InRange(src, minScalar, maxScalar, dst);
//int count = Cv2.CountNonZero(dst);
//labelCount.Text = count + "";
//src.CopyTo(dst, dst);
//imageBoxEx1.Image = BitmapConverter.ToBitmap(dst);
}
private void minR_ValueChanged(object sender, EventArgs e)
{
InRangeImage();
}
private void maxR_ValueChanged(object sender, EventArgs e)
{
InRangeImage();
}
private void minG_ValueChanged(object sender, EventArgs e)
{
InRangeImage();
}
private void maxG_ValueChanged(object sender, EventArgs e)
{
InRangeImage();
}
private void minB_ValueChanged(object sender, EventArgs e)
{
InRangeImage();
}
private void maxB_ValueChanged(object sender, EventArgs e)
{
InRangeImage();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
using Cyotek.Windows.Forms;

using Acc.ImageBox;
namespace AccAOI
{
......@@ -40,7 +42,7 @@ namespace AccAOI
this.btnGetCameraImg = new Asa.Theme.FlatButton();
this.comType = new Asa.Theme.FlatCombo();
this.panAoi = new System.Windows.Forms.Panel();
this.imageBox1 = new Cyotek.Windows.Forms.ImageBox();
this.imageBox1 = new AccImageBox();
this.btnExcute = new Asa.Theme.FlatButton();
this.SuspendLayout();
//
......@@ -163,7 +165,7 @@ namespace AccAOI
| System.Windows.Forms.AnchorStyles.Right)));
this.imageBox1.Location = new System.Drawing.Point(625, 40);
this.imageBox1.Name = "imageBox1";
this.imageBox1.SelectionMode = Cyotek.Windows.Forms.ImageBoxSelectionMode.Rectangle;
this.imageBox1.SelectionMode = ImageBoxSelectionMode.Rectangle;
this.imageBox1.Size = new System.Drawing.Size(637, 592);
this.imageBox1.TabIndex = 4;
this.imageBox1.SelectionRegionChanged += new System.EventHandler(this.imageBox1_SelectionRegionChanged);
......@@ -207,7 +209,7 @@ namespace AccAOI
#endregion
private Asa.Theme.FlatList aoiList;
private ImageBox imageBox1;
private AccImageBox imageBox1;
private Asa.Theme.FlatButton btnOpenPro;
private Asa.Theme.FlatButton btnSavePro;
private Asa.Theme.FlatButton btnNewAoi;
......
using Cyotek.Windows.Forms;

using Acc.ImageBox;
namespace AccAOI.control
{
......@@ -38,7 +40,7 @@ namespace AccAOI.control
this.panAreaImage = new Asa.Theme.FlatPanel();
this.panControl = new Asa.Theme.FlatPanel();
this.btnImgType = new Asa.Theme.FlatButton();
this.aoiImage = new Cyotek.Windows.Forms.ImageBox();
this.aoiImage = new ImageBox();
this.panAreaSet.SuspendLayout();
this.SuspendLayout();
//
......
......@@ -7,9 +7,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cyotek.Windows.Forms;
using AOI;
using System.Drawing.Drawing2D;
using Acc.ImageBox;
namespace AccAOI.control
{
......
using System.Drawing;
namespace AccAOI
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// http://cyotek.com
// http://cyotek.com/blog/tag/imagebox
// 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.
public class DragHandle
{
#region Public Constructors
public DragHandle(DragHandleAnchor anchor)
: this()
{
this.Anchor = anchor;
}
#endregion
#region Protected Constructors
protected DragHandle()
{
this.Enabled = true;
this.Visible = true;
}
#endregion
#region Public Properties
public DragHandleAnchor Anchor { get; protected set; }
public Rectangle Bounds { get; set; }
public bool Enabled { get; set; }
public bool Visible { get; set; }
#endregion
}
}
namespace AccAOI
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// http://cyotek.com
// http://cyotek.com/blog/tag/imagebox
// 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.
public enum DragHandleAnchor
{
None,
TopLeft,
TopCenter,
TopRight,
MiddleLeft,
MiddleCenter,
MiddleRight,
BottomLeft,
BottomCenter,
BottomRight
}
}
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
namespace AccAOI
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// http://cyotek.com
// http://cyotek.com/blog/tag/imagebox
// 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.
public class DragHandleCollection : IEnumerable<DragHandle>
{
#region Instance Fields
private readonly IDictionary<DragHandleAnchor, DragHandle> _items;
#endregion
#region Public Constructors
public DragHandleCollection()
{
_items = new Dictionary<DragHandleAnchor, DragHandle>();
_items.Add(DragHandleAnchor.TopLeft, new DragHandle(DragHandleAnchor.TopLeft));
_items.Add(DragHandleAnchor.TopCenter, new DragHandle(DragHandleAnchor.TopCenter));
_items.Add(DragHandleAnchor.TopRight, new DragHandle(DragHandleAnchor.TopRight));
_items.Add(DragHandleAnchor.MiddleLeft, new DragHandle(DragHandleAnchor.MiddleLeft));
_items.Add(DragHandleAnchor.MiddleRight, new DragHandle(DragHandleAnchor.MiddleRight));
_items.Add(DragHandleAnchor.BottomLeft, new DragHandle(DragHandleAnchor.BottomLeft));
_items.Add(DragHandleAnchor.BottomCenter, new DragHandle(DragHandleAnchor.BottomCenter));
_items.Add(DragHandleAnchor.BottomRight, new DragHandle(DragHandleAnchor.BottomRight));
_items.Add(DragHandleAnchor.MiddleCenter, new DragHandle(DragHandleAnchor.MiddleCenter));
}
#endregion
#region Public Properties
public int Count
{
get { return _items.Count; }
}
public DragHandle this[DragHandleAnchor index]
{
get { return _items[index]; }
}
#endregion
#region Public Members
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns>
/// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
/// </returns>
public IEnumerator<DragHandle> GetEnumerator()
{
return _items.Values.GetEnumerator();
}
public DragHandleAnchor HitTest(Point point)
{
DragHandleAnchor result;
result = DragHandleAnchor.None;
foreach (DragHandle handle in this)
{
if (handle.Visible && handle.Bounds.Contains(point))
{
result = handle.Anchor;
break;
}
}
return result;
}
#endregion
#region IEnumerable<DragHandle> Members
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>
/// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
/// </returns>
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
#endregion
}
}
//using Cyotek.Windows.Forms;
//using System;
//using System.ComponentModel;
//using System.Drawing;
//using System.Windows.Forms;
//namespace AccAOI
//{
// // Cyotek ImageBox
// // Copyright (c) 2010-2014 Cyotek.
// // http://cyotek.com
// // http://cyotek.com/blog/tag/imagebox
// // 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.
// public class ImageBoxEx : ImageBox
// {
// public void CleearArea()
// {
// }
// #region Instance Fields
// private readonly DragHandleCollection _dragHandles;
// private int _dragHandleSize;
// private Size _minimumSelectionSize;
// #endregion
// #region Public Constructors
// public ImageBoxEx()
// {
// _dragHandles = new DragHandleCollection();
// this.DragHandleSize = 9;
// this.MinimumSelectionSize = Size.Empty;
// this.PositionDragHandles();
// }
// #endregion
// #region Events
// /// <summary>
// /// Occurs when the DragHandleSize property value changes
// /// </summary>
// [Category("Property Changed")]
// public event EventHandler DragHandleSizeChanged;
// /// <summary>
// /// Occurs when the MinimumSelectionSize property value changes
// /// </summary>
// [Category("Property Changed")]
// public event EventHandler MinimumSelectionSizeChanged;
// [Category("Action")]
// public event EventHandler SelectionMoved;
// [Category("Action")]
// public event CancelEventHandler SelectionMoving;
// [Category("Action")]
// public event EventHandler SelectionResized;
// [Category("Action")]
// public event CancelEventHandler SelectionResizing;
// #endregion
// #region Overridden Methods
// /// <summary>
// /// Raises the <see cref="System.Windows.Forms.Control.MouseDown" /> event.
// /// </summary>
// /// <param name="e">
// /// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
// /// </param>
// protected override void OnMouseDown(MouseEventArgs e)
// {
// Point imagePoint;
// imagePoint = this.PointToImage(e.Location);
// if (e.Button == MouseButtons.Left && (this.SelectionRegion.Contains(imagePoint) || this.HitTest(e.Location) != DragHandleAnchor.None))
// {
// this.DragOrigin = e.Location;
// this.DragOriginOffset = new Point(imagePoint.X - (int)this.SelectionRegion.X, imagePoint.Y - (int)this.SelectionRegion.Y);
// }
// else
// {
// this.DragOriginOffset = Point.Empty;
// this.DragOrigin = Point.Empty;
// }
// base.OnMouseDown(e);
// }
// /// <summary>
// /// Raises the <see cref="System.Windows.Forms.Control.MouseMove" /> event.
// /// </summary>
// /// <param name="e">
// /// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
// /// </param>
// protected override void OnMouseMove(MouseEventArgs e)
// {
// // 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))
// {
// DragHandleAnchor anchor;
// anchor = this.HitTest(this.DragOrigin);
// if (anchor == DragHandleAnchor.None)
// {
// // move
// this.StartMove();
// }
// else if (this.DragHandles[anchor].Enabled && this.DragHandles[anchor].Visible)
// {
// // resize
// this.StartResize(anchor);
// }
// }
// // set the cursor
// this.SetCursor(e.Location);
// // perform operations
// this.ProcessSelectionMove(e.Location);
// this.ProcessSelectionResize(e.Location);
// base.OnMouseMove(e);
// }
// /// <summary>
// /// Raises the <see cref="System.Windows.Forms.Control.MouseUp" /> event.
// /// </summary>
// /// <param name="e">
// /// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
// /// </param>
// protected override void OnMouseUp(MouseEventArgs e)
// {
// if (this.IsMoving)
// {
// this.CompleteMove();
// }
// else if (this.IsResizing)
// {
// this.CompleteResize();
// }
// base.OnMouseUp(e);
// }
// /// <summary>
// /// Raises the <see cref="System.Windows.Forms.Control.Paint" /> event.
// /// </summary>
// /// <param name="e">
// /// A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.
// /// </param>
// protected override void OnPaint(PaintEventArgs e)
// {
// base.OnPaint(e);
// if (this.AllowPainting && !this.SelectionRegion.IsEmpty)
// {
// foreach (DragHandle handle in this.DragHandles)
// {
// if (handle.Visible)
// {
// this.DrawDragHandle(e.Graphics, handle);
// }
// }
// }
// }
// /// <summary>
// /// Raises the <see cref="System.Windows.Forms.Control.Resize" /> event.
// /// </summary>
// /// <param name="e">
// /// An <see cref="T:System.EventArgs" /> that contains the event data.
// /// </param>
// protected override void OnResize(EventArgs e)
// {
// base.OnResize(e);
// this.PositionDragHandles();
// }
// /// <summary>
// /// Raises the <see cref="System.Windows.Forms.ScrollableControl.Scroll" /> event.
// /// </summary>
// /// <param name="se">
// /// A <see cref="T:System.Windows.Forms.ScrollEventArgs" /> that contains the event data.
// /// </param>
// protected override void OnScroll(ScrollEventArgs se)
// {
// base.OnScroll(se);
// this.PositionDragHandles();
// }
// /// <summary>
// /// Raises the <see cref="ImageBox.Selecting" /> event.
// /// </summary>
// /// <param name="e">
// /// The <see cref="System.EventArgs" /> instance containing the event data.
// /// </param>
// 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;
// base.OnSelecting(e);
// }
// /// <summary>
// /// Raises the <see cref="ImageBox.SelectionRegionChanged" /> event.
// /// </summary>
// /// <param name="e">
// /// The <see cref="System.EventArgs" /> instance containing the event data.
// /// </param>
// protected override void OnSelectionRegionChanged(EventArgs e)
// {
// base.OnSelectionRegionChanged(e);
// this.PositionDragHandles();
// }
// /// <summary>
// /// Raises the <see cref="ImageBox.ZoomChanged" /> event.
// /// </summary>
// /// <param name="e">
// /// The <see cref="System.EventArgs" /> instance containing the event data.
// /// </param>
// protected override void OnZoomChanged(EventArgs e)
// {
// base.OnZoomChanged(e);
// this.PositionDragHandles();
// }
// /// <summary>
// /// Processes a dialog key.
// /// </summary>
// /// <returns>
// /// true if the key was processed by the control; otherwise, false.
// /// </returns>
// /// <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)
// {
// bool result;
// if (keyData == Keys.Escape && (this.IsResizing || this.IsMoving))
// {
// if (this.IsResizing)
// {
// this.CancelResize();
// }
// else
// {
// this.CancelMove();
// }
// result = true;
// }
// else
// {
// result = base.ProcessDialogKey(keyData);
// }
// return result;
// }
// #endregion
// #region Public Properties
// [Category("Appearance")]
// [DefaultValue(8)]
// public virtual int DragHandleSize
// {
// get { return _dragHandleSize; }
// set
// {
// if (this.DragHandleSize != value)
// {
// _dragHandleSize = value;
// this.OnDragHandleSizeChanged(EventArgs.Empty);
// }
// }
// }
// [Browsable(false)]
// public DragHandleCollection DragHandles
// {
// get { return _dragHandles; }
// }
// [Browsable(false)]
// [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
// public bool IsMoving { get; protected set; }
// [Browsable(false)]
// [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
// public bool IsResizing { get; protected set; }
// [Category("Behavior")]
// [DefaultValue(typeof(Size), "0, 0")]
// public virtual Size MinimumSelectionSize
// {
// get { return _minimumSelectionSize; }
// set
// {
// if (this.MinimumSelectionSize != value)
// {
// _minimumSelectionSize = value;
// this.OnMinimumSelectionSizeChanged(EventArgs.Empty);
// }
// }
// }
// [Browsable(false)]
// public RectangleF PreviousSelectionRegion { get; protected set; }
// #endregion
// #region Protected Properties
// protected Point DragOrigin { get; set; }
// protected Point DragOriginOffset { get; set; }
// protected DragHandleAnchor ResizeAnchor { get; set; }
// #endregion
// #region Public Members
// public void CancelResize()
// {
// this.SelectionRegion = this.PreviousSelectionRegion;
// this.CompleteResize();
// }
// public void StartMove()
// {
// CancelEventArgs e;
// if (this.IsMoving || this.IsResizing)
// {
// throw new InvalidOperationException("A move or resize action is currently being performed.");
// }
// e = new CancelEventArgs();
// this.OnSelectionMoving(e);
// if (!e.Cancel)
// {
// this.PreviousSelectionRegion = this.SelectionRegion;
// this.IsMoving = true;
// }
// }
// #endregion
// #region Protected Members
// protected virtual void DrawDragHandle(Graphics graphics, DragHandle handle)
// {
// int left;
// int top;
// int width;
// int height;
// Pen outerPen;
// Brush innerBrush;
// left = handle.Bounds.Left;
// top = handle.Bounds.Top;
// width = handle.Bounds.Width;
// height = handle.Bounds.Height;
// if (handle.Enabled)
// {
// outerPen = SystemPens.WindowFrame;
// innerBrush = SystemBrushes.Window;
// }
// else
// {
// outerPen = SystemPens.ControlDark;
// innerBrush = SystemBrushes.Control;
// }
// 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, top + 1, left, top + height - 2);
// 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);
// }
// /// <summary>
// /// Raises the <see cref="DragHandleSizeChanged" /> event.
// /// </summary>
// /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
// protected virtual void OnDragHandleSizeChanged(EventArgs e)
// {
// EventHandler handler;
// this.PositionDragHandles();
// this.Invalidate();
// handler = this.DragHandleSizeChanged;
// if (handler != null)
// {
// handler(this, e);
// }
// }
// /// <summary>
// /// Raises the <see cref="MinimumSelectionSizeChanged" /> event.
// /// </summary>
// /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
// protected virtual void OnMinimumSelectionSizeChanged(EventArgs e)
// {
// EventHandler handler;
// handler = this.MinimumSelectionSizeChanged;
// if (handler != null)
// {
// handler(this, e);
// }
// }
// /// <summary>
// /// Raises the <see cref="SelectionMoved" /> event.
// /// </summary>
// /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
// protected virtual void OnSelectionMoved(EventArgs e)
// {
// EventHandler handler;
// handler = this.SelectionMoved;
// if (handler != null)
// {
// handler(this, e);
// }
// }
// /// <summary>
// /// Raises the <see cref="SelectionMoving" /> event.
// /// </summary>
// /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
// protected virtual void OnSelectionMoving(CancelEventArgs e)
// {
// CancelEventHandler handler;
// handler = this.SelectionMoving;
// if (handler != null)
// {
// handler(this, e);
// }
// }
// /// <summary>
// /// Raises the <see cref="SelectionResized" /> event.
// /// </summary>
// /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
// protected virtual void OnSelectionResized(EventArgs e)
// {
// EventHandler handler;
// handler = this.SelectionResized;
// if (handler != null)
// {
// handler(this, e);
// }
// }
// /// <summary>
// /// Raises the <see cref="SelectionResizing" /> event.
// /// </summary>
// /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
// protected virtual void OnSelectionResizing(CancelEventArgs e)
// {
// CancelEventHandler handler;
// handler = this.SelectionResizing;
// if (handler != null)
// {
// handler(this, e);
// }
// }
// #endregion
// #region Private Members
// private void CancelMove()
// {
// this.SelectionRegion = this.PreviousSelectionRegion;
// this.CompleteMove();
// }
// private void CompleteMove()
// {
// this.ResetDrag();
// this.OnSelectionMoved(EventArgs.Empty);
// }
// private void CompleteResize()
// {
// this.ResetDrag();
// this.OnSelectionResized(EventArgs.Empty);
// }
// private DragHandleAnchor HitTest(Point cursorPosition)
// {
// return this.DragHandles.HitTest(cursorPosition);
// }
// private bool IsOutsideDragZone(Point location)
// {
// Rectangle dragZone;
// int dragWidth;
// int dragHeight;
// dragWidth = SystemInformation.DragSize.Width;
// dragHeight = SystemInformation.DragSize.Height;
// dragZone = new Rectangle(this.DragOrigin.X - (dragWidth / 2), this.DragOrigin.Y - (dragHeight / 2), dragWidth, dragHeight);
// return !dragZone.Contains(location);
// }
// private void PositionDragHandles()
// {
// if (this.DragHandles != null && this.DragHandleSize > 0)
// {
// if (this.SelectionRegion.IsEmpty)
// {
// foreach (DragHandle handle in this.DragHandles)
// {
// handle.Bounds = Rectangle.Empty;
// }
// }
// else
// {
// int left;
// int top;
// int right;
// int bottom;
// int halfWidth;
// int halfHeight;
// int halfDragHandleSize;
// Rectangle viewport;
// int offsetX;
// int offsetY;
// viewport = this.GetImageViewPort();
// offsetX = viewport.Left + this.Padding.Left + this.AutoScrollPosition.X;
// offsetY = viewport.Top + this.Padding.Top + this.AutoScrollPosition.Y;
// halfDragHandleSize = this.DragHandleSize / 2;
// left = Convert.ToInt32((this.SelectionRegion.Left * this.ZoomFactor) + offsetX);
// top = Convert.ToInt32((this.SelectionRegion.Top * this.ZoomFactor) + offsetY);
// right = left + Convert.ToInt32(this.SelectionRegion.Width * this.ZoomFactor);
// bottom = top + Convert.ToInt32(this.SelectionRegion.Height * this.ZoomFactor);
// halfWidth = Convert.ToInt32(this.SelectionRegion.Width * 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.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.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.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.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);
// }
// }
// }
// private void ProcessSelectionMove(Point cursorPosition)
// {
// if (this.IsMoving)
// {
// int x;
// int y;
// Point imagePoint;
// imagePoint = this.PointToImage(cursorPosition, true);
// x = Math.Max(0, imagePoint.X - this.DragOriginOffset.X);
// if (x + this.SelectionRegion.Width >= this.ViewSize.Width)
// {
// x = this.ViewSize.Width - (int)this.SelectionRegion.Width;
// }
// y = Math.Max(0, imagePoint.Y - this.DragOriginOffset.Y);
// if (y + this.SelectionRegion.Height >= this.ViewSize.Height)
// {
// y = this.ViewSize.Height - (int)this.SelectionRegion.Height;
// }
// this.SelectionRegion = new RectangleF(x, y, this.SelectionRegion.Width, this.SelectionRegion.Height);
// }
// }
// private void ProcessSelectionResize(Point cursorPosition)
// {
// if (this.IsResizing)
// {
// Point imagePosition;
// float left;
// float top;
// float right;
// float bottom;
// bool resizingTopEdge;
// bool resizingBottomEdge;
// bool resizingLeftEdge;
// bool resizingRightEdge;
// imagePosition = this.PointToImage(cursorPosition, true);
// // get the current selection
// left = this.SelectionRegion.Left;
// top = this.SelectionRegion.Top;
// right = this.SelectionRegion.Right;
// bottom = this.SelectionRegion.Bottom;
// // decide which edges we're resizing
// resizingTopEdge = this.ResizeAnchor >= DragHandleAnchor.TopLeft && this.ResizeAnchor <= DragHandleAnchor.TopRight;
// resizingBottomEdge = this.ResizeAnchor >= DragHandleAnchor.BottomLeft && this.ResizeAnchor <= DragHandleAnchor.BottomRight;
// 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;
// // and resize!
// if (resizingTopEdge)
// {
// top = imagePosition.Y;
// if (bottom - top < this.MinimumSelectionSize.Height)
// {
// top = bottom - this.MinimumSelectionSize.Height;
// }
// }
// else if (resizingBottomEdge)
// {
// bottom = imagePosition.Y;
// if (bottom - top < this.MinimumSelectionSize.Height)
// {
// bottom = top + this.MinimumSelectionSize.Height;
// }
// }
// if (resizingLeftEdge)
// {
// left = imagePosition.X;
// if (right - left < this.MinimumSelectionSize.Width)
// {
// left = right - this.MinimumSelectionSize.Width;
// }
// }
// else if (resizingRightEdge)
// {
// right = imagePosition.X;
// if (right - left < this.MinimumSelectionSize.Width)
// {
// right = left + this.MinimumSelectionSize.Width;
// }
// }
// this.SelectionRegion = new RectangleF(left, top, right - left, bottom - top);
// }
// }
// private void ResetDrag()
// {
// this.IsResizing = false;
// this.IsMoving = false;
// this.DragOrigin = Point.Empty;
// this.DragOriginOffset = Point.Empty;
// }
// private void SetCursor(Point point)
// {
// Cursor cursor;
// if (this.IsSelecting)
// {
// cursor = Cursors.Default;
// }
// else
// {
// DragHandleAnchor handleAnchor;
// handleAnchor = this.IsResizing ? this.ResizeAnchor : this.HitTest(point);
// if (handleAnchor != DragHandleAnchor.None && this.DragHandles[handleAnchor].Enabled)
// {
// switch (handleAnchor)
// {
// case DragHandleAnchor.TopLeft:
// case DragHandleAnchor.BottomRight:
// cursor = Cursors.SizeNWSE;
// break;
// case DragHandleAnchor.TopCenter:
// case DragHandleAnchor.BottomCenter:
// cursor = Cursors.SizeNS;
// break;
// case DragHandleAnchor.TopRight:
// case DragHandleAnchor.BottomLeft:
// cursor = Cursors.SizeNESW;
// break;
// case DragHandleAnchor.MiddleLeft:
// case DragHandleAnchor.MiddleRight:
// cursor = Cursors.SizeWE;
// break;
// case DragHandleAnchor.MiddleCenter:
// cursor = Cursors.Cross;
// break;
// default:
// throw new ArgumentOutOfRangeException();
// }
// }
// else if (this.IsMoving || this.SelectionRegion.Contains(this.PointToImage(point)))
// {
// cursor = Cursors.SizeAll;
// }
// else
// {
// cursor = Cursors.Default;
// }
// }
// this.Cursor = cursor;
// }
// private void StartResize(DragHandleAnchor anchor)
// {
// CancelEventArgs e;
// if (this.IsMoving || this.IsResizing)
// {
// throw new InvalidOperationException("A move or resize action is currently being performed.");
// }
// e = new CancelEventArgs();
// this.OnSelectionResizing(e);
// if (!e.Cancel)
// {
// this.ResizeAnchor = anchor;
// this.PreviousSelectionRegion = this.SelectionRegion;
// this.IsResizing = true;
// }
// }
// #endregion
// }
//}
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// http://cyotek.com
// http://cyotek.com/blog/tag/ImageBox
// 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.
public class AccImageBox : ImageBox
{
#region Instance Fields
//private readonly DragHandleCollection _dragHandles;
private int _dragHandleSize;
private Size _minimumSelectionSize;
#endregion
#region Public Constructors
public AccImageBox()
{
//_dragHandles = new DragHandleCollection();
this.DragHandleSize = 9;
this.MinimumSelectionSize = Size.Empty;
//this.PositionDragHandles();
}
#endregion
#region Events
/// <summary>
/// Occurs when the DragHandleSize property value changes
/// </summary>
[Category("Property Changed")]
public event EventHandler DragHandleSizeChanged;
/// <summary>
/// Occurs when the MinimumSelectionSize property value changes
/// </summary>
[Category("Property Changed")]
public event EventHandler MinimumSelectionSizeChanged;
[Category("Action")]
public event EventHandler SelectionMoved;
[Category("Action")]
public event CancelEventHandler SelectionMoving;
[Category("Action")]
public event EventHandler SelectionResized;
[Category("Action")]
public event CancelEventHandler SelectionResizing;
#endregion
#region Overridden Methods
private bool IsInSelectionRegion(Point cursorLocation, out PointF pathPoint)
{
pathPoint = PointF.Empty;
if (this.SelectionRegion.PointCount > 0)
{
var imagePoint = this.PointToImage(cursorLocation);
PointF[] points = this.SelectionRegion.PathPoints;
foreach (PointF p in points)
{
RectangleF recf = new RectangleF(p.X - this.DragHandleSize / 2, p.Y - this.DragHandleSize / 2, this.DragHandleSize, this.DragHandleSize);
if (recf.Contains(imagePoint))
{
pathPoint = p;
return false;
}
}
if (this.SelectionRegion.IsVisible(imagePoint))
{
return true;
}
}
return false;
}
/// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.MouseDown" /> event.
/// </summary>
/// <param name="e">
/// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
/// </param>
protected override void OnMouseDown(MouseEventArgs e)
{
bool inSelectionRegion = IsInSelectionRegion(e.Location, out PointF pathPoint);
if (e.Button == MouseButtons.Left && (inSelectionRegion || !pathPoint.IsEmpty))
{
this.DragOrigin = e.Location;
//this.DragOriginOffset = new Point(imagePoint.X - (int)this.SelectionRegion.X, imagePoint.Y - (int)this.SelectionRegion.Y);
}
else
{
//this.DragOriginOffset = Point.Empty;
this.DragOrigin = Point.Empty;
}
base.OnMouseDown(e);
}
/// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.MouseMove" /> event.
/// </summary>
/// <param name="e">
/// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
/// </param>
protected override void OnMouseMove(MouseEventArgs e)
{
// 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))
{
bool inSelectionRegion = IsInSelectionRegion(e.Location, out PointF pathPoint);
if (inSelectionRegion)
{
// move
this.StartMove();
}
else if (!pathPoint.IsEmpty)
{
// resize
this.StartResize(pathPoint);
}
}
// set the cursor
this.SetCursor(e.Location);
// perform operations
this.ProcessSelectionMove(e.Location);
this.ProcessSelectionResize(e.Location);
base.OnMouseMove(e);
}
/// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.MouseUp" /> event.
/// </summary>
/// <param name="e">
/// A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.
/// </param>
protected override void OnMouseUp(MouseEventArgs e)
{
if (this.IsMoving)
{
this.CompleteMove();
}
else if (this.IsResizing)
{
this.CompleteResize();
}
base.OnMouseUp(e);
}
/// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.Paint" /> event.
/// </summary>
/// <param name="e">
/// A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.
/// </param>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.AllowPainting)
{
if (base.SelectionRegion.PointCount > 0)
{
PointF[] points = base.SelectionRegion.PathPoints;
Rectangle viewport = this.GetImageViewPort();
int offsetX = viewport.Left + this.Padding.Left + this.AutoScrollPosition.X;
int offsetY = viewport.Top + this.Padding.Top + this.AutoScrollPosition.Y;
Matrix matrix = new Matrix();
matrix.Translate(offsetX, offsetY);
matrix.Scale((float)this.ZoomFactor, (float)this.ZoomFactor);
matrix.TransformPoints(points);
foreach (PointF point in points)
{
this.DrawDragHandle(e.Graphics, point);
}
}
}
}
/// <summary>
/// Raises the <see cref="System.Windows.Forms.Control.Resize" /> event.
/// </summary>
/// <param name="e">
/// An <see cref="T:System.EventArgs" /> that contains the event data.
/// </param>
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
//this.PositionDragHandles();
}
/// <summary>
/// Raises the <see cref="System.Windows.Forms.ScrollableControl.Scroll" /> event.
/// </summary>
/// <param name="se">
/// A <see cref="T:System.Windows.Forms.ScrollEventArgs" /> that contains the event data.
/// </param>
protected override void OnScroll(ScrollEventArgs se)
{
base.OnScroll(se);
//this.PositionDragHandles();
}
/// <summary>
/// Raises the <see cref="ImageBox.Selecting" /> event.
/// </summary>
/// <param name="e">
/// The <see cref="System.EventArgs" /> instance containing the event data.
/// </param>
protected override void OnSelecting(ImageBoxCancelEventArgs e)
{
bool inSelectionRegion = IsInSelectionRegion(e.Location, out PointF pathPoint);
e.Cancel = this.IsMoving || this.IsResizing || this.SelectionRegion.IsVisible(this.PointToImage(e.Location)) || pathPoint != PointF.Empty;
base.OnSelecting(e);
}
/// <summary>
/// Raises the <see cref="ImageBox.SelectionRegionChanged" /> event.
/// </summary>
/// <param name="e">
/// The <see cref="System.EventArgs" /> instance containing the event data.
/// </param>
protected override void OnSelectionRegionChanged(EventArgs e)
{
base.OnSelectionRegionChanged(e);
//this.PositionDragHandles();
}
/// <summary>
/// Raises the <see cref="ImageBox.ZoomChanged" /> event.
/// </summary>
/// <param name="e">
/// The <see cref="System.EventArgs" /> instance containing the event data.
/// </param>
protected override void OnZoomChanged(EventArgs e)
{
base.OnZoomChanged(e);
//this.PositionDragHandles();
}
/// <summary>
/// Processes a dialog key.
/// </summary>
/// <returns>
/// true if the key was processed by the control; otherwise, false.
/// </returns>
/// <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)
{
bool result;
if (keyData == Keys.Escape && (this.IsResizing || this.IsMoving))
{
if (this.IsResizing)
{
this.CancelResize();
}
else
{
this.CancelMove();
}
result = true;
}
else
{
result = base.ProcessDialogKey(keyData);
}
return result;
}
#endregion
#region Public Properties
[Category("Appearance")]
[DefaultValue(8)]
public virtual int DragHandleSize
{
get { return _dragHandleSize; }
set
{
if (this.DragHandleSize != value)
{
_dragHandleSize = value;
this.OnDragHandleSizeChanged(EventArgs.Empty);
}
}
}
//[Browsable(false)]
//public DragHandleCollection DragHandles
//{
//get { return _dragHandles; }
// }
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsMoving { get; protected set; }
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsResizing { get; protected set; }
[Category("Behavior")]
[DefaultValue(typeof(Size), "0, 0")]
public virtual Size MinimumSelectionSize
{
get { return _minimumSelectionSize; }
set
{
if (this.MinimumSelectionSize != value)
{
_minimumSelectionSize = value;
this.OnMinimumSelectionSizeChanged(EventArgs.Empty);
}
}
}
[Browsable(false)]
public GraphicsPath PreviousSelectionRegion { get; protected set; }
#endregion
#region Protected Properties
protected Point DragOrigin { get; set; }
//protected Point DragOriginOffset { get; set; }
protected PointF ResizePoint { get; set; }
#endregion
#region Public Members
public void CancelResize()
{
this.SelectionRegion = this.PreviousSelectionRegion;
this.CompleteResize();
}
public void StartMove()
{
CancelEventArgs e;
if (this.IsMoving || this.IsResizing)
{
throw new InvalidOperationException("A move or resize action is currently being performed.");
}
e = new CancelEventArgs();
this.OnSelectionMoving(e);
if (!e.Cancel)
{
this.PreviousSelectionRegion = this.SelectionRegion;
this.IsMoving = true;
}
}
#endregion
#region Protected Members
/// <summary>
/// 画改变大小的点
/// </summary>
/// <param name="graphics"></param>
/// <param name="pointf"></param>
protected virtual void DrawDragHandle(Graphics graphics, PointF pointf)
{
float left = pointf.X - this.DragHandleSize / 2;
float top = pointf.Y - this.DragHandleSize / 2;
float width = this.DragHandleSize;
float height = this.DragHandleSize;
Pen outerPen = SystemPens.WindowFrame;
Brush innerBrush = SystemBrushes.Window;
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, top + 1, left, top + height - 2);
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);
}
/// <summary>
/// Raises the <see cref="DragHandleSizeChanged" /> event.
/// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnDragHandleSizeChanged(EventArgs e)
{
EventHandler handler;
//this.PositionDragHandles();
this.Invalidate();
handler = this.DragHandleSizeChanged;
if (handler != null)
{
handler(this, e);
}
}
/// <summary>
/// Raises the <see cref="MinimumSelectionSizeChanged" /> event.
/// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnMinimumSelectionSizeChanged(EventArgs e)
{
EventHandler handler;
handler = this.MinimumSelectionSizeChanged;
if (handler != null)
{
handler(this, e);
}
}
/// <summary>
/// Raises the <see cref="SelectionMoved" /> event.
/// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnSelectionMoved(EventArgs e)
{
EventHandler handler;
handler = this.SelectionMoved;
if (handler != null)
{
handler(this, e);
}
}
/// <summary>
/// Raises the <see cref="SelectionMoving" /> event.
/// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnSelectionMoving(CancelEventArgs e)
{
CancelEventHandler handler;
handler = this.SelectionMoving;
if (handler != null)
{
handler(this, e);
}
}
/// <summary>
/// Raises the <see cref="SelectionResized" /> event.
/// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnSelectionResized(EventArgs e)
{
EventHandler handler;
handler = this.SelectionResized;
if (handler != null)
{
handler(this, e);
}
}
/// <summary>
/// Raises the <see cref="SelectionResizing" /> event.
/// </summary>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected virtual void OnSelectionResizing(CancelEventArgs e)
{
CancelEventHandler handler;
handler = this.SelectionResizing;
if (handler != null)
{
handler(this, e);
}
}
#endregion
#region Private Members
private void CancelMove()
{
this.SelectionRegion = this.PreviousSelectionRegion;
this.CompleteMove();
}
private void CompleteMove()
{
this.ResetDrag();
this.OnSelectionMoved(EventArgs.Empty);
}
private void CompleteResize()
{
this.ResetDrag();
this.OnSelectionResized(EventArgs.Empty);
}
//private DragHandleAnchor HitTest(Point cursorPosition)
//{
// return this.DragHandles.HitTest(cursorPosition);
//}
private bool IsOutsideDragZone(Point location)
{
Rectangle dragZone;
int dragWidth;
int dragHeight;
dragWidth = SystemInformation.DragSize.Width;
dragHeight = SystemInformation.DragSize.Height;
dragZone = new Rectangle(this.DragOrigin.X - (dragWidth / 2), this.DragOrigin.Y - (dragHeight / 2), dragWidth, dragHeight);
return !dragZone.Contains(location);
}
//private void PositionDragHandles()
//{
// if (this.DragHandles != null && this.DragHandleSize > 0)
// {
// if (this.SelectionRegion.PointCount == 0)
// {
// foreach (DragHandle handle in this.DragHandles)
// {
// handle.Bounds = Rectangle.Empty;
// }
// }
// else
// {
// int left;
// int top;
// int right;
// int bottom;
// int halfWidth;
// int halfHeight;
// int halfDragHandleSize;
// Rectangle viewport;
// int offsetX;
// int offsetY;
// viewport = this.GetImageViewPort();
// offsetX = viewport.Left + this.Padding.Left + this.AutoScrollPosition.X;
// offsetY = viewport.Top + this.Padding.Top + this.AutoScrollPosition.Y;
// halfDragHandleSize = this.DragHandleSize / 2;
// //left = Convert.ToInt32((this.SelectionRegion.Left * this.ZoomFactor) + offsetX);
// //top = Convert.ToInt32((this.SelectionRegion.Top * this.ZoomFactor) + offsetY);
// //right = left + Convert.ToInt32(this.SelectionRegion.Width * this.ZoomFactor);
// //bottom = top + Convert.ToInt32(this.SelectionRegion.Height * this.ZoomFactor);
// //halfWidth = Convert.ToInt32(this.SelectionRegion.Width * 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.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.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.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.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);
// }
// }
//}
private void ProcessSelectionMove(Point cursorPosition)
{
if (this.IsMoving)
{
GraphicsPath path = new GraphicsPath(this.SelectionRegion.PathPoints, this.SelectionRegion.PathTypes);
Point startPoint = this.PointToImage(this.DragOrigin, true);
Point endPoint = this.PointToImage(cursorPosition, true);
Matrix matrix = new Matrix();
matrix.Translate(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y);
path.Transform(matrix);
this.DragOrigin = cursorPosition;
this.SelectionRegion = path;
//x = Math.Max(0, imagePoint.X - this.DragOriginOffset.X);
//if (x + this.SelectionRegion.Width >= this.ViewSize.Width)
//{
// x = this.ViewSize.Width - (int)this.SelectionRegion.Width;
//}
//y = Math.Max(0, imagePoint.Y - this.DragOriginOffset.Y);
//if (y + this.SelectionRegion.Height >= this.ViewSize.Height)
//{
// y = this.ViewSize.Height - (int)this.SelectionRegion.Height;
//}
//this.SelectionRegion = new RectangleF(x, y, this.SelectionRegion.Width, this.SelectionRegion.Height);
}
}
private void ProcessSelectionResize(Point cursorPosition)
{
if (this.IsResizing)
{
if (Control.ModifierKeys == Keys.Alt)
{
//自由变形
Point endPoint = this.PointToImage(cursorPosition, true);
PointF[] pathPoints = this.SelectionRegion.PathPoints;
for (int i = 0; i < pathPoints.Length; i++)
{
PointF p = pathPoints[i];
if (p.X == this.ResizePoint.X && p.Y == this.ResizePoint.Y)
{
pathPoints[i] = endPoint;
this.ResizePoint = endPoint;
break;
}
}
GraphicsPath path = new GraphicsPath(pathPoints, this.SelectionRegion.PathTypes);
this.SelectionRegion = path;
}
else
{
//按比例缩放
GraphicsPath path = new GraphicsPath(this.SelectionRegion.PathPoints, this.SelectionRegion.PathTypes);
Point startPoint = this.PointToImage(this.DragOrigin, true);
Point endPoint = this.PointToImage(cursorPosition, true);
Matrix matrix = new Matrix();
float scaleX = endPoint.X * 1.0f / startPoint.X;
float scaleY = endPoint.Y * 1.0f / startPoint.Y;
matrix.Scale(scaleX, scaleY);
path.Transform(matrix);
var oldBounds = this.SelectionRegion.GetBounds();
var newBounds = path.GetBounds();
var oldCenterX = oldBounds.X + oldBounds.Width / 2;
var oldCenterY = oldBounds.Y + oldBounds.Height / 2;
var newCenterX = newBounds.X + newBounds.Width / 2;
var newCenterY = newBounds.Y + newBounds.Height / 2;
matrix.Reset();
matrix.Translate(oldCenterX-newCenterX, oldCenterY - newCenterY);
path.Transform(matrix);
this.DragOrigin = cursorPosition;
this.SelectionRegion = path;
}
}
}
private void ResetDrag()
{
this.IsResizing = false;
this.IsMoving = false;
this.DragOrigin = Point.Empty;
//this.DragOriginOffset = Point.Empty;
}
private void SetCursor(Point point)
{
Cursor cursor = Cursors.Default;
if (IsMoving)
{
cursor = Cursors.SizeAll;
}else if (IsResizing)
{
cursor = Cursors.NoMove2D;
}
else
{
bool inSelectionRegion = IsInSelectionRegion(point, out PointF pathPoint);
if (inSelectionRegion)
{
cursor = Cursors.SizeAll;
}
else if (!pathPoint.IsEmpty)
{
cursor = Cursors.NoMove2D;
}
}
this.Cursor = cursor;
}
private void StartResize(PointF anchor)
{
CancelEventArgs e;
if (this.IsMoving || this.IsResizing)
{
throw new InvalidOperationException("A move or resize action is currently being performed.");
}
e = new CancelEventArgs();
this.OnSelectionResizing(e);
if (!e.Cancel)
{
this.ResizePoint = anchor;
this.PreviousSelectionRegion = this.SelectionRegion;
this.IsResizing = true;
}
}
#endregion
}
}
......@@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ImageBox</RootNamespace>
<AssemblyName>ImageBox</AssemblyName>
<AssemblyName>AccImageBox</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
......@@ -46,31 +46,35 @@
<Compile Include="ImageBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ImageBox\ImageBoxActionSources.cs" />
<Compile Include="ImageBox\ImageBoxBorderStyle.cs" />
<Compile Include="ImageBox\ImageBoxCancelEventArgs.cs" />
<Compile Include="ImageBox\ImageBoxGridDisplayMode.cs" />
<Compile Include="ImageBox\ImageBoxGridScale.cs" />
<Compile Include="ImageBox\ImageBoxNativeMethods.cs" />
<Compile Include="ImageBox\ImageBoxSelectionMode.cs" />
<Compile Include="ImageBox\ImageBoxSizeMode.cs" />
<Compile Include="ImageBox\ImageBoxZoomActions.cs" />
<Compile Include="ImageBox\ImageBoxZoomEventArgs.cs" />
<Compile Include="AccImageBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="box\ImageBoxActionSources.cs" />
<Compile Include="box\ImageBoxBorderStyle.cs" />
<Compile Include="box\ImageBoxCancelEventArgs.cs" />
<Compile Include="box\ImageBoxGridDisplayMode.cs" />
<Compile Include="box\ImageBoxGridScale.cs" />
<Compile Include="box\ImageBoxNativeMethods.cs" />
<Compile Include="box\ImageBoxSelectionMode.cs" />
<Compile Include="box\ImageBoxSizeMode.cs" />
<Compile Include="box\ImageBoxZoomActions.cs" />
<Compile Include="box\ImageBoxZoomEventArgs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ImageBox\ScrollControl.cs">
<Compile Include="box\ScrollControl.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ImageBox\ScrollProperties.cs">
<Compile Include="box\ScrollProperties.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ImageBox\VirtualScrollableControl.cs">
<Compile Include="box\VirtualScrollableControl.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ImageBox\ZoomLevelCollection.cs" />
<Compile Include="ImageBox\ZoomLevelCollectionConverter.cs" />
<Compile Include="box\ZoomLevelCollection.cs" />
<Compile Include="box\ZoomLevelCollectionConverter.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="ImageBox.bmp" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -4,14 +4,14 @@ using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......@@ -21,7 +21,7 @@ namespace Cyotek.Windows.Forms
[DefaultProperty("Image")]
[ToolboxBitmap(typeof(ImageBox), "ImageBox.bmp")]
[ToolboxItem(true)]
/* [Designer("Cyotek.Windows.Forms.Design.ImageBoxDesigner", Cyotek.Windows.Forms.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */
/* [Designer("Acc.ImageBox.Design.ImageBoxDesigner", Acc.ImageBox.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */
public class ImageBox : VirtualScrollableControl
{
#region Constants
......@@ -813,7 +813,7 @@ namespace Cyotek.Windows.Forms
{
int spins;
// The MouseWheel event can contain multiple "spins" of the wheel so we need to adjust accordingly
// The MouseWheel event can contain multiple "spins" of the wheel so we need to adjust Acc.ImageBoxordingly
spins = Math.Abs(e.Delta / SystemInformation.MouseWheelScrollDelta);
// TODO: Really should update the source method to handle multiple increments rather than calling it multiple times
......@@ -895,7 +895,7 @@ namespace Cyotek.Windows.Forms
// draw the selection
if (this.SelectionRegion != null && this.SelectionRegion.PointCount > 0)
if (this.SelectionRegion.PointCount > 0)
{
this.DrawSelection(e);
}
......@@ -1457,9 +1457,9 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Gets or sets a value indicating whether the font size of text is scaled according to the current zoom level.
/// Gets or sets a value indicating whether the font size of text is scaled Acc.ImageBoxording to the current zoom level.
/// </summary>
/// <value><c>true</c> if the size of text is scaled according to the current zoom level; otherwise, <c>false</c>.</value>
/// <value><c>true</c> if the size of text is scaled Acc.ImageBoxording to the current zoom level; otherwise, <c>false</c>.</value>
[Category("Appearance")]
[DefaultValue(false)]
public virtual bool ScaleText
......@@ -1535,8 +1535,10 @@ namespace Cyotek.Windows.Forms
{
if (this.SelectionRegion != value)
{
if(value == null) {
value = new GraphicsPath();
}
_selectionRegion = value;
this.OnSelectionRegionChanged(EventArgs.Empty);
}
}
......@@ -2152,7 +2154,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.RectangleF" /> scaled according to the current zoom level and repositioned to include the current image offset
/// Returns the source <see cref="T:System.Drawing.RectangleF" /> scaled Acc.ImageBoxording to the current zoom level and repositioned to include the current image offset
/// </summary>
/// <param name="source">The source <see cref="RectangleF"/> to offset.</param>
/// <returns>A <see cref="RectangleF"/> which has been resized and repositioned to match the current zoom level and image offset</returns>
......@@ -2172,7 +2174,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source rectangle scaled according to the current zoom level and repositioned to include the current image offset
/// Returns the source rectangle scaled Acc.ImageBoxording to the current zoom level and repositioned to include the current image offset
/// </summary>
/// <param name="x">The X co-ordinate of the source rectangle.</param>
/// <param name="y">The Y co-ordinate of the source rectangle.</param>
......@@ -2185,7 +2187,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source rectangle scaled according to the current zoom level and repositioned to include the current image offset
/// Returns the source rectangle scaled Acc.ImageBoxording to the current zoom level and repositioned to include the current image offset
/// </summary>
/// <param name="x">The X co-ordinate of the source rectangle.</param>
/// <param name="y">The Y co-ordinate of the source rectangle.</param>
......@@ -2198,7 +2200,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.Rectangle" /> scaled according to the current zoom level and repositioned to include the current image offset
/// Returns the source <see cref="T:System.Drawing.Rectangle" /> scaled Acc.ImageBoxording to the current zoom level and repositioned to include the current image offset
/// </summary>
/// <param name="source">The source <see cref="Rectangle"/> to offset.</param>
/// <returns>A <see cref="Rectangle"/> which has been resized and repositioned to match the current zoom level and image offset</returns>
......@@ -2218,7 +2220,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.Point" /> scaled according to the current zoom level
/// Returns the source <see cref="T:System.Drawing.Point" /> scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="x">The X co-ordinate of the point to scale.</param>
/// <param name="y">The Y co-ordinate of the point to scale.</param>
......@@ -2229,7 +2231,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.Point" /> scaled according to the current zoom level
/// Returns the source <see cref="T:System.Drawing.Point" /> scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="x">The X co-ordinate of the point to scale.</param>
/// <param name="y">The Y co-ordinate of the point to scale.</param>
......@@ -2240,7 +2242,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.Point" /> scaled according to the current zoom level
/// Returns the source <see cref="T:System.Drawing.Point" /> scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="source">The source <see cref="Point"/> to scale.</param>
/// <returns>A <see cref="Point"/> which has been scaled to match the current zoom level</returns>
......@@ -2250,7 +2252,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.PointF" /> scaled according to the current zoom level
/// Returns the source <see cref="T:System.Drawing.PointF" /> scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="source">The source <see cref="PointF"/> to scale.</param>
/// <returns>A <see cref="PointF"/> which has been scaled to match the current zoom level</returns>
......@@ -2260,7 +2262,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source rectangle scaled according to the current zoom level
/// Returns the source rectangle scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="x">The X co-ordinate of the source rectangle.</param>
/// <param name="y">The Y co-ordinate of the source rectangle.</param>
......@@ -2273,7 +2275,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source rectangle scaled according to the current zoom level
/// Returns the source rectangle scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="x">The X co-ordinate of the source rectangle.</param>
/// <param name="y">The Y co-ordinate of the source rectangle.</param>
......@@ -2286,7 +2288,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source rectangle scaled according to the current zoom level
/// Returns the source rectangle scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="location">The location of the source rectangle.</param>
/// <param name="size">The size of the source rectangle.</param>
......@@ -2297,7 +2299,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source rectangle scaled according to the current zoom level
/// Returns the source rectangle scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="location">The location of the source rectangle.</param>
/// <param name="size">The size of the source rectangle.</param>
......@@ -2308,7 +2310,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.Rectangle" /> scaled according to the current zoom level
/// Returns the source <see cref="T:System.Drawing.Rectangle" /> scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="source">The source <see cref="Rectangle"/> to scale.</param>
/// <returns>A <see cref="Rectangle"/> which has been scaled to match the current zoom level</returns>
......@@ -2318,7 +2320,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.RectangleF" /> scaled according to the current zoom level
/// Returns the source <see cref="T:System.Drawing.RectangleF" /> scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="source">The source <see cref="RectangleF"/> to scale.</param>
/// <returns>A <see cref="RectangleF"/> which has been scaled to match the current zoom level</returns>
......@@ -2328,7 +2330,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source size scaled according to the current zoom level
/// Returns the source size scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="width">The width of the size to scale.</param>
/// <param name="height">The height of the size to scale.</param>
......@@ -2339,7 +2341,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source size scaled according to the current zoom level
/// Returns the source size scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="width">The width of the size to scale.</param>
/// <param name="height">The height of the size to scale.</param>
......@@ -2350,7 +2352,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.SizeF" /> scaled according to the current zoom level
/// Returns the source <see cref="T:System.Drawing.SizeF" /> scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="source">The source <see cref="SizeF"/> to scale.</param>
/// <returns>A <see cref="SizeF"/> which has been resized to match the current zoom level</returns>
......@@ -2360,7 +2362,7 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Returns the source <see cref="T:System.Drawing.Size" /> scaled according to the current zoom level
/// Returns the source <see cref="T:System.Drawing.Size" /> scaled Acc.ImageBoxording to the current zoom level
/// </summary>
/// <param name="source">The source <see cref="Size"/> to scale.</param>
/// <returns>A <see cref="Size"/> which has been resized to match the current zoom level</returns>
......@@ -3057,7 +3059,7 @@ namespace Cyotek.Windows.Forms
/// <param name="backColor">The <see cref="Color"/> to apply to the area represented by <c>bounds</c>.</param>
/// <param name="textAlign">The <see cref="ContentAlignment"/> to apply to the text.</param>
/// <param name="bounds">The <see cref="Rectangle"/> that represents the bounds of the text.</param>
/// <param name="scaleText">If set to <c>true</c> the font size is scaled according to the current zoom level.</param>
/// <param name="scaleText">If set to <c>true</c> the font size is scaled Acc.ImageBoxording to the current zoom level.</param>
protected virtual void DrawLabel(Graphics graphics, string text, Font font, Color foreColor, Color backColor, ContentAlignment textAlign, Rectangle bounds, bool scaleText)
{
TextFormatFlags flags;
......@@ -3174,9 +3176,6 @@ namespace Cyotek.Windows.Forms
matrix.Translate(offsetX, offsetY);
newPath.Transform(matrix);
//rect = this.GetOffsetRectangle(this.SelectionRegion);
using (Brush brush = new SolidBrush(Color.FromArgb(128, this.SelectionColor)))
......@@ -4214,15 +4213,26 @@ namespace Cyotek.Windows.Forms
y = y / (float)this.ZoomFactor;
w = w / (float)this.ZoomFactor;
h = h / (float)this.ZoomFactor;
if (Control.ModifierKeys == Keys.Shift)
{
w = h = w < h ? h : w;
}
selection = new RectangleF(x, y, w, h);
if (this.LimitSelectionToImage)
{
selection = this.FitRectangle(selection);
}
GraphicsPath path = new GraphicsPath();
Region re = new Region();
path.AddRectangle(selection);
switch (this.SelectionMode)
{
case ImageBoxSelectionMode.Rectangle:
path.AddRectangle(selection);
break;
case ImageBoxSelectionMode.Eclipse:
path.AddEllipse(selection);
break;
}
this.SelectionRegion = path;
}
}
......
using System;
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......
using System.ComponentModel;
using System.Drawing;
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......
using System;
using System.Runtime.InteropServices;
// ReSharper disable NotAccessedField.Global
// ReSharper disable NotAcc.ImageBoxessedField.Global
// ReSharper disable InconsistentNaming
// ReSharper disable FieldCanBeMadeReadOnly.Global
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......@@ -155,7 +155,7 @@ namespace Cyotek.Windows.Forms
#endregion
}
// ReSharper restore NotAccessedField.Global
// ReSharper restore NotAcc.ImageBoxessedField.Global
// ReSharper restore FieldCanBeMadeReadOnly.Global
// ReSharper restore InconsistentNaming
}
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......@@ -15,7 +15,7 @@
public enum ImageBoxSizeMode
{
/// <summary>
/// The image is disiplayed according to current zoom and scroll properties.
/// The image is disiplayed Acc.ImageBoxording to current zoom and scroll properties.
/// </summary>
Normal,
......
using System;
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......
using System;
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// 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.
......
......@@ -11,7 +11,7 @@ using Cyotek.Win32;
// Original ScrollControl code by Scott Crawford (http://sukiware.com/)
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
/// <summary>
/// Defines a base class for controls that support scrolling behavior.
......
......@@ -2,7 +2,7 @@
// Original ScrollControl code by Scott Crawford (http://sukiware.com/)
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
partial class ScrollControl
{
......
......@@ -5,7 +5,7 @@ using System.Windows.Forms;
// Original VirtualScrollableControl code by Scott Crawford (http://sukiware.com/)
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
/// <summary>
/// Defines a base class for controls that support auto-scrolling behavior.
......@@ -327,7 +327,7 @@ namespace Cyotek.Windows.Forms
#region Protected Members
/// <summary>
/// Adjusts the given Point according to the scroll size
/// Adjusts the given Point Acc.ImageBoxording to the scroll size
/// </summary>
/// <param name="position">The position.</param>
/// <returns></returns>
......
......@@ -2,7 +2,7 @@
using System.Collections;
using System.Collections.Generic;
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
/// <summary>
/// Represents available levels of zoom in an <see cref="ImageBox"/> control
......
......@@ -9,7 +9,7 @@ using System.Reflection;
using System.Text;
using System.Windows.Forms;
namespace Cyotek.Windows.Forms
namespace Acc.ImageBox
{
public class ZoomLevelCollectionConverter
: TypeConverter
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!