Commit 5245bd9e SK

merge

2 个父辈 538dd72a b94db01c
......@@ -10,10 +10,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AOI</RootNamespace>
<AssemblyName>AOI</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
......
......@@ -12,6 +12,7 @@ namespace AOI
{
public abstract class AoiMethod
{
public string MethodName { get; set; }
/// <summary>
/// 兴趣区域路径
/// </summary>
......
......@@ -82,5 +82,7 @@ namespace AOI
this.methodMap = JsonUtil.DeserializeJsonToObject<Dictionary<string, AoiMethod>>(methodMapJson);
}
}
}
......@@ -6,7 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AOI.rgb
namespace AOI
{
/// <summary>
/// 颜色抽取
......@@ -14,10 +14,10 @@ namespace AOI.rgb
public class AoiMethodRgb : AoiMethod
{
public int minR = 1;
public int maxR = 1;
public int maxR = 255;
public int minG = 1;
public int maxG = 255;
public int minB = 255;
public int minB = 1;
public int maxB = 255;
/// <summary>
/// 抽取出的像素最小占比
......
......@@ -8,8 +8,9 @@
<OutputType>WinExe</OutputType>
<RootNamespace>AccAOI</RootNamespace>
<AssemblyName>AccAOI</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
......@@ -31,6 +32,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Asa.Theme">
<HintPath>..\dll\Asa.Theme.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
......@@ -44,12 +48,43 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="control\AioMarkControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="control\AioMarkControl.Designer.cs">
<DependentUpon>AioMarkControl.cs</DependentUpon>
</Compile>
<Compile Include="control\AoiBlobControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="control\AoiBlobControl.Designer.cs">
<DependentUpon>AoiBlobControl.cs</DependentUpon>
</Compile>
<Compile Include="control\ABaseControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="control\ABaseControl.Designer.cs">
<DependentUpon>ABaseControl.cs</DependentUpon>
</Compile>
<Compile Include="control\AoiRgbControl.cs">
<SubType>UserControl</SubType>
</Compile>
<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>
<Compile Include="FrmAoiSetting.Designer.cs">
<DependentUpon>FrmAoiSetting.cs</DependentUpon>
</Compile>
<Compile Include="FormUtil.cs" />
<Compile Include="imageBoxEx\DragHandle.cs" />
<Compile Include="imageBoxEx\DragHandleAnchor.cs" />
<Compile Include="imageBoxEx\DragHandleCollection.cs" />
......@@ -58,9 +93,24 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="control\AioMarkControl.resx">
<DependentUpon>AioMarkControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="control\AoiBlobControl.resx">
<DependentUpon>AoiBlobControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="control\ABaseControl.resx">
<DependentUpon>ABaseControl.cs</DependentUpon>
</EmbeddedResource>
<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>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
......@@ -69,6 +119,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
......@@ -93,5 +144,6 @@
<Name>ImageBox</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
</configuration>
\ No newline at end of file
</configuration>
......@@ -30,7 +30,6 @@
{
this.buttonOpen = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.imageBox = new ImageBoxEx();
this.R = new System.Windows.Forms.Label();
this.maxR = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
......@@ -40,8 +39,9 @@
this.maxG = new System.Windows.Forms.NumericUpDown();
this.minB = new System.Windows.Forms.NumericUpDown();
this.maxB = new System.Windows.Forms.NumericUpDown();
this.imageBoxEx1 = new ImageBoxEx();
this.labelCount = new System.Windows.Forms.Label();
this.imageBoxEx1 = new AccAOI.ImageBoxEx();
this.imageBox = new AccAOI.ImageBoxEx();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.maxR)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.minR)).BeginInit();
......@@ -72,21 +72,6 @@
this.panel1.Size = new System.Drawing.Size(457, 388);
this.panel1.TabIndex = 3;
//
// 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);
//
// R
//
this.R.AutoSize = true;
......@@ -207,6 +192,15 @@
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;
......@@ -215,14 +209,20 @@
this.imageBoxEx1.Size = new System.Drawing.Size(230, 159);
this.imageBoxEx1.TabIndex = 21;
//
// labelCount
// imageBox
//
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";
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
//
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AccAOI
{
public class FormUtil
{
public static int GetIntValue(Asa.Theme.FlatText text)
{
int value = 0;
try
{
value = int.Parse(text.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
}
}
namespace AccAOI
{
partial class FrmAoiSetting
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.aoiList = new Asa.Theme.FlatList();
this.btnOpenPro = new Asa.Theme.FlatButton();
this.btnSavePro = new Asa.Theme.FlatButton();
this.btnNewAoi = new Asa.Theme.FlatButton();
this.btnOpenImage = new Asa.Theme.FlatButton();
this.flatLabel1 = new Asa.Theme.FlatLabel();
this.cmbCameraList = new Asa.Theme.FlatCombo();
this.btnGetCameraImg = new Asa.Theme.FlatButton();
this.comType = new Asa.Theme.FlatCombo();
this.panAoi = new System.Windows.Forms.Panel();
this.imageBox1 = new AccAOI.ImageBoxEx();
this.SuspendLayout();
//
// aoiList
//
this.aoiList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.aoiList.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.aoiList.Index = -1;
this.aoiList.Inside = false;
this.aoiList.Location = new System.Drawing.Point(9, 202);
this.aoiList.Name = "aoiList";
this.aoiList.Size = new System.Drawing.Size(287, 430);
this.aoiList.TabIndex = 2;
this.aoiList.IndexChanged += new System.EventHandler(this.aoiList_IndexChanged);
//
// btnOpenPro
//
this.btnOpenPro.ImageSize = new System.Drawing.Size(0, 0);
this.btnOpenPro.Inside = false;
this.btnOpenPro.Location = new System.Drawing.Point(28, 115);
this.btnOpenPro.Name = "btnOpenPro";
this.btnOpenPro.Size = new System.Drawing.Size(109, 30);
this.btnOpenPro.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnOpenPro.TabIndex = 6;
this.btnOpenPro.Text = "打开项目";
this.btnOpenPro.Click += new System.EventHandler(this.btnOpenPro_Click);
//
// btnSavePro
//
this.btnSavePro.ImageSize = new System.Drawing.Size(0, 0);
this.btnSavePro.Inside = false;
this.btnSavePro.Location = new System.Drawing.Point(153, 115);
this.btnSavePro.Name = "btnSavePro";
this.btnSavePro.Size = new System.Drawing.Size(109, 30);
this.btnSavePro.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnSavePro.TabIndex = 7;
this.btnSavePro.Text = "保存项目";
this.btnSavePro.Click += new System.EventHandler(this.btnSavePro_Click);
//
// btnNewAoi
//
this.btnNewAoi.ImageSize = new System.Drawing.Size(0, 0);
this.btnNewAoi.Inside = false;
this.btnNewAoi.Location = new System.Drawing.Point(153, 151);
this.btnNewAoi.Name = "btnNewAoi";
this.btnNewAoi.Size = new System.Drawing.Size(109, 30);
this.btnNewAoi.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnNewAoi.TabIndex = 8;
this.btnNewAoi.Text = "新增";
this.btnNewAoi.Click += new System.EventHandler(this.btnNewAoi_Click);
//
// btnOpenImage
//
this.btnOpenImage.ImageSize = new System.Drawing.Size(0, 0);
this.btnOpenImage.Inside = false;
this.btnOpenImage.Location = new System.Drawing.Point(28, 79);
this.btnOpenImage.Name = "btnOpenImage";
this.btnOpenImage.Size = new System.Drawing.Size(109, 30);
this.btnOpenImage.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnOpenImage.TabIndex = 10;
this.btnOpenImage.Text = "打开本地图片";
this.btnOpenImage.Click += new System.EventHandler(this.btnOpenImage_Click);
//
// flatLabel1
//
this.flatLabel1.Inside = false;
this.flatLabel1.Location = new System.Drawing.Point(23, 43);
this.flatLabel1.Name = "flatLabel1";
this.flatLabel1.Size = new System.Drawing.Size(80, 30);
this.flatLabel1.TabIndex = 11;
this.flatLabel1.Text = "相机列表";
//
// cmbCameraList
//
this.cmbCameraList.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.cmbCameraList.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbCameraList.Inside = false;
this.cmbCameraList.Location = new System.Drawing.Point(104, 43);
this.cmbCameraList.Name = "cmbCameraList";
this.cmbCameraList.Size = new System.Drawing.Size(158, 30);
this.cmbCameraList.TabIndex = 12;
//
// btnGetCameraImg
//
this.btnGetCameraImg.ImageSize = new System.Drawing.Size(0, 0);
this.btnGetCameraImg.Inside = false;
this.btnGetCameraImg.Location = new System.Drawing.Point(153, 79);
this.btnGetCameraImg.Name = "btnGetCameraImg";
this.btnGetCameraImg.Size = new System.Drawing.Size(109, 30);
this.btnGetCameraImg.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnGetCameraImg.TabIndex = 13;
this.btnGetCameraImg.Text = "相机获取图片";
this.btnGetCameraImg.Click += new System.EventHandler(this.btnGetCameraImg_Click);
//
// comType
//
this.comType.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.comType.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.comType.Inside = false;
this.comType.Location = new System.Drawing.Point(28, 151);
this.comType.Name = "comType";
this.comType.Size = new System.Drawing.Size(109, 30);
this.comType.TabIndex = 14;
//
// panAoi
//
this.panAoi.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.panAoi.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(4)))), ((int)(((byte)(4)))), ((int)(((byte)(4)))));
this.panAoi.Location = new System.Drawing.Point(302, 40);
this.panAoi.Name = "panAoi";
this.panAoi.Size = new System.Drawing.Size(317, 592);
this.panAoi.TabIndex = 15;
//
// imageBox1
//
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.Right)));
this.imageBox1.DragHandleSize = 9;
this.imageBox1.Location = new System.Drawing.Point(625, 40);
this.imageBox1.Name = "imageBox1";
this.imageBox1.SelectionMode = Cyotek.Windows.Forms.ImageBoxSelectionMode.Rectangle;
this.imageBox1.Size = new System.Drawing.Size(637, 592);
this.imageBox1.TabIndex = 4;
this.imageBox1.SelectionRegionChanged += new System.EventHandler(this.imageBox1_SelectionRegionChanged);
//
// FrmAoiSetting
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(1271, 641);
this.Controls.Add(this.panAoi);
this.Controls.Add(this.comType);
this.Controls.Add(this.btnGetCameraImg);
this.Controls.Add(this.cmbCameraList);
this.Controls.Add(this.flatLabel1);
this.Controls.Add(this.btnOpenImage);
this.Controls.Add(this.btnNewAoi);
this.Controls.Add(this.btnSavePro);
this.Controls.Add(this.btnOpenPro);
this.Controls.Add(this.imageBox1);
this.Controls.Add(this.aoiList);
this.Location = new System.Drawing.Point(0, 0);
this.Minimized = true;
this.Name = "FrmAoiSetting";
this.Text = "AOI";
this.Load += new System.EventHandler(this.FrmAoiSetting_Load);
this.Controls.SetChildIndex(this.aoiList, 0);
this.Controls.SetChildIndex(this.imageBox1, 0);
this.Controls.SetChildIndex(this.btnOpenPro, 0);
this.Controls.SetChildIndex(this.btnSavePro, 0);
this.Controls.SetChildIndex(this.btnNewAoi, 0);
this.Controls.SetChildIndex(this.btnOpenImage, 0);
this.Controls.SetChildIndex(this.flatLabel1, 0);
this.Controls.SetChildIndex(this.cmbCameraList, 0);
this.Controls.SetChildIndex(this.btnGetCameraImg, 0);
this.Controls.SetChildIndex(this.comType, 0);
this.Controls.SetChildIndex(this.panAoi, 0);
this.ResumeLayout(false);
}
#endregion
private Asa.Theme.FlatList aoiList;
private ImageBoxEx imageBox1;
private Asa.Theme.FlatButton btnOpenPro;
private Asa.Theme.FlatButton btnSavePro;
private Asa.Theme.FlatButton btnNewAoi;
private Asa.Theme.FlatButton btnOpenImage;
private Asa.Theme.FlatLabel flatLabel1;
private Asa.Theme.FlatCombo cmbCameraList;
private Asa.Theme.FlatButton btnGetCameraImg;
private Asa.Theme.FlatCombo comType;
private System.Windows.Forms.Panel panAoi;
}
}
\ No newline at end of file
using AOI;
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 FrmAoiSetting : Asa.Theme.FlatForm
{
private control.ABaseControl aoiControl = null;
private Image Img = null;
private AoiProject Project = null;
public FrmAoiSetting()
{
InitializeComponent();
this.WindowState = FormWindowState.Maximized;
}
public FrmAoiSetting(string programPath, Image image = null)
{
InitializeComponent();
this.WindowState = FormWindowState.Maximized;
if (!programPath.Equals("") && (image != null))
{
Project = new AoiProject(image);
Project.Load(programPath);
}
ShowPorject();
}
private void FrmAoiSetting_Load(object sender, EventArgs e)
{
comType.ItemAdd("Mark点设置");
comType.ItemAdd("斑点分析");
comType.ItemAdd("颜色抽取");
comType.Text = "Mark点设置";
}
private void btnOpenImage_Click(object sender, EventArgs e)
{
System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog();
openDialog.Title = "打开本地图片";
openDialog.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 (*.*)|*.*";
openDialog.DefaultExt = "png";
//openDialog.DefaultExt = "png";
System.Windows.Forms.DialogResult result = openDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
string fileName = openDialog.FileName;
//读取图片内容
this.Img = (Image)Image.FromFile(fileName).Clone();
imageBox1.Image = Img;
}
private void btnGetCameraImg_Click(object sender, EventArgs e)
{
string camera = cmbCameraList.Text;
if (camera.Equals(""))
{
MessageBox.Show("清先选择相机");
return;
}
}
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();
openDialog.Title = "打开项目";
openDialog.Filter = "(*.data)|*.data|(*.*)|*.*";
//openDialog.DefaultExt = "png";
System.Windows.Forms.DialogResult result = openDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
string fileName = openDialog.FileName;
Project = new AoiProject(this.Img);
Project.Load(fileName);
ShowPorject();
}
private void btnSavePro_Click(object sender, EventArgs e)
{
if (this.Project == null)
{
MessageBox.Show("没有项目可保存");
return;
}
SaveCurrAoi();
System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
saveFileDialog.Title = "保存项目";
saveFileDialog.Filter = "(*.data)|*.data|(*.*)|*.*";
//openDialog.DefaultExt = "png";
System.Windows.Forms.DialogResult result = saveFileDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
string fileName = saveFileDialog.FileName;
Project.Save(fileName);
MessageBox.Show("保存成功");
}
private void btnNewAoi_Click(object sender, EventArgs e)
{
if (this.Img == null)
{
MessageBox.Show("清先打开图片");
return;
}
if (this.Project == null)
{
Project = new AoiProject(this.Img);
}
if (comType.Text.Equals(""))
{
MessageBox.Show("请选择类型");
comType.Focus();
return;
}
string text = comType.Text;
CloseCurrAoi();
AoiMethod methodInfo = null;
if (text.Equals("Mark点设置"))
{
methodInfo = new AoiMarkMethod();
}
else if (text.Equals("斑点分析"))
{
methodInfo = new AoiBlobMethod();
}
else
{
methodInfo = new AoiMethodRgb();
}
methodInfo.MethodName = Project.methodMap.Values.Count.ToString().PadLeft(2, '0') + "_" + text;
Project.methodMap.Add(methodInfo.MethodName, methodInfo);
ShowAoi(methodInfo);
aoiList.ItemAdd(aoiControl.TitleName);
}
private void ShowAoi(AoiMethod method)
{
if (aoiControl == null)
{
if(method is AoiBlobMethod)
{
aoiControl = new control.AoiBlobControl();
}else if(method is AoiMarkMethod)
{
aoiControl = new control.AioMarkControl();
}else if(method is AoiMethodRgb)
{
aoiControl = new control.AoiRgbControl();
}
}
this.aoiControl.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)));
aoiControl.FormBorderStyle = FormBorderStyle.None;
aoiControl.StartPosition = FormStartPosition.CenterParent;
aoiControl.Location = new Point(0, 0);
aoiControl.SetImageBox(this.imageBox1);
aoiControl.AoiInfo = method;
aoiControl.Size = panAoi.Size;
aoiControl.TitleName = method.MethodName;
aoiControl.TopLevel = false;
aoiControl.Parent = panAoi;
aoiControl.Show();
aoiControl.ShowAoiInfo();
if (method.RoiPath != null)
{
currPath = method.RoiPath;
imageBox1.SelectionRegion = method.RoiPath.GetBounds();
Image threshImage = CutImage(imageBox1.Image, currPath);
cutImage = threshImage;
aoiControl.currPath = currPath;
aoiControl.aoiImage.Image = threshImage;
}
}
private void SaveCurrAoi()
{
if (aoiControl != null &&aoiControl.Visible)
{
AoiMethod method = aoiControl.GetAoiInfo();
//更新
if (Project.methodMap.ContainsKey(method.MethodName))
{
Project.methodMap[method.MethodName] = method;
}
}
}
private void CloseCurrAoi()
{
SaveCurrAoi();
if (aoiControl != null)
{
if (aoiControl.Visible)
{
aoiControl.Close();
}
aoiControl.Dispose();
aoiControl = null;
}
}
private void ShowPorject()
{
if (Project != null)
{
aoiList.ItemClear();
if (Project.methodMap.Count > 0)
{
foreach(string key in Project.methodMap.Keys)
{
aoiList.ItemAdd(key);
}
aoiList.Index = 0;
}
}
}
private void aoiList_IndexChanged(object sender, EventArgs e)
{
int index = aoiList.Index;
if (index >= 0 && (Project != null))
{
List<AoiMethod> methods = new List<AoiMethod>(Project.methodMap.Values);
if (index < methods.Count)
{
AoiMethod method = methods[index];
if (aoiControl != null && aoiControl.TitleName.Equals(method.MethodName))
{
return;
}
else
{
CloseCurrAoi();
ShowAoi(method);
}
}
}
}
private Image cutImage = null;
private GraphicsPath currPath = null;
private void imageBox1_SelectionRegionChanged(object sender, EventArgs e)
{
try
{
if (imageBox1.Image == null || this.Img == null || aoiControl == null)
{
return;
}
Matrix translateMatrix = new Matrix();
translateMatrix.Translate(100, 0);
RectangleF region = imageBox1.SelectionRegion;
currPath = new GraphicsPath();
if (aoiControl.AreaType.Equals(1))
{
currPath.AddRectangle(region);
}
else
{
currPath.AddEllipse(region);
}
Image threshImage = CutImage(imageBox1.Image, currPath);
cutImage = threshImage;
aoiControl.currPath = currPath;
aoiControl.aoiImage.Image = threshImage;
}catch(Exception ex)
{
}
}
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;
}
}
}
<?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
......@@ -16,7 +16,7 @@ namespace AccAOI
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new FrmAoiSetting());
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace AccAOI.Properties
{
namespace AccAOI.Properties {
using System;
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AccAOI.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 覆盖当前线程的 CurrentUICulture 属性
/// 使用此强类型的资源类的资源查找
/// 重写当前线程的 CurrentUICulture 属性
/// 重写当前线程的 CurrentUICulture 属性
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set
{
set {
resourceCulture = value;
}
}
......
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace AccAOI.Properties
{
namespace AccAOI.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
public static Settings Default {
get {
return defaultInstance;
}
}
......
namespace AccAOI.control
{
partial class ABaseControl
{
/// <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 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.panControl = new Asa.Theme.FlatPanel();
this.panAreaImage = new Asa.Theme.FlatPanel();
this.panAreaSet = new Asa.Theme.FlatPanel();
this.panParam = new Asa.Theme.FlatPanel();
this.panResult = new Asa.Theme.FlatPanel();
this.btnClearArea = new Asa.Theme.FlatButton();
this.btnSetArea = new Asa.Theme.FlatButton();
this.btnYuan = new Asa.Theme.FlatButton();
this.aoiImage = new AccAOI.ImageBoxEx();
this.SuspendLayout();
//
// panControl
//
this.panControl.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.panControl.Inside = false;
this.panControl.Location = new System.Drawing.Point(0, 0);
this.panControl.Name = "panControl";
this.panControl.Size = new System.Drawing.Size(308, 696);
this.panControl.TabIndex = 0;
this.panControl.Text = "斑点分析";
//
// panAreaImage
//
this.panAreaImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panAreaImage.Inside = false;
this.panAreaImage.Location = new System.Drawing.Point(4, 27);
this.panAreaImage.Name = "panAreaImage";
this.panAreaImage.Size = new System.Drawing.Size(298, 212);
this.panAreaImage.TabIndex = 1;
this.panAreaImage.Text = "区域图片";
//
// panAreaSet
//
this.panAreaSet.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panAreaSet.Inside = false;
this.panAreaSet.Location = new System.Drawing.Point(4, 244);
this.panAreaSet.Name = "panAreaSet";
this.panAreaSet.Size = new System.Drawing.Size(298, 69);
this.panAreaSet.TabIndex = 3;
this.panAreaSet.Text = "区域设置-矩形";
//
// panParam
//
this.panParam.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panParam.Inside = false;
this.panParam.Location = new System.Drawing.Point(4, 319);
this.panParam.Name = "panParam";
this.panParam.Size = new System.Drawing.Size(298, 167);
this.panParam.TabIndex = 4;
this.panParam.Text = "参数设置";
//
// panResult
//
this.panResult.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.panResult.Inside = false;
this.panResult.Location = new System.Drawing.Point(4, 491);
this.panResult.Name = "panResult";
this.panResult.Size = new System.Drawing.Size(298, 197);
this.panResult.TabIndex = 5;
this.panResult.Text = "结果判断";
//
// btnClearArea
//
this.btnClearArea.ImageSize = new System.Drawing.Size(0, 0);
this.btnClearArea.Inside = false;
this.btnClearArea.Location = new System.Drawing.Point(204, 274);
this.btnClearArea.Name = "btnClearArea";
this.btnClearArea.Size = new System.Drawing.Size(90, 30);
this.btnClearArea.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnClearArea.TabIndex = 6;
this.btnClearArea.Text = "清除";
this.btnClearArea.Click += new System.EventHandler(this.btnClearArea_Click);
//
// btnSetArea
//
this.btnSetArea.ImageSize = new System.Drawing.Size(0, 0);
this.btnSetArea.Inside = false;
this.btnSetArea.Location = new System.Drawing.Point(12, 274);
this.btnSetArea.Name = "btnSetArea";
this.btnSetArea.Size = new System.Drawing.Size(90, 30);
this.btnSetArea.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnSetArea.TabIndex = 7;
this.btnSetArea.Text = "矩形";
this.btnSetArea.Click += new System.EventHandler(this.btnSetArea_Click);
//
// btnYuan
//
this.btnYuan.ImageSize = new System.Drawing.Size(0, 0);
this.btnYuan.Inside = false;
this.btnYuan.Location = new System.Drawing.Point(108, 274);
this.btnYuan.Name = "btnYuan";
this.btnYuan.Size = new System.Drawing.Size(90, 30);
this.btnYuan.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnYuan.TabIndex = 8;
this.btnYuan.Text = "椭圆";
this.btnYuan.Click += new System.EventHandler(this.btnYuan_Click);
//
// aoiImage
//
this.aoiImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.aoiImage.DragHandleSize = 9;
this.aoiImage.Location = new System.Drawing.Point(9, 53);
this.aoiImage.Name = "aoiImage";
this.aoiImage.Size = new System.Drawing.Size(288, 182);
this.aoiImage.TabIndex = 2;
//
// ABaseControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.ClientSize = new System.Drawing.Size(312, 700);
this.Controls.Add(this.btnYuan);
this.Controls.Add(this.btnSetArea);
this.Controls.Add(this.btnClearArea);
this.Controls.Add(this.panResult);
this.Controls.Add(this.panParam);
this.Controls.Add(this.panAreaSet);
this.Controls.Add(this.aoiImage);
this.Controls.Add(this.panAreaImage);
this.Controls.Add(this.panControl);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "ABaseControl";
this.ResumeLayout(false);
}
#endregion
private Asa.Theme.FlatPanel panAreaImage;
private Asa.Theme.FlatPanel panAreaSet;
private Asa.Theme.FlatButton btnClearArea;
private Asa.Theme.FlatButton btnSetArea;
private Asa.Theme.FlatPanel panControl;
protected Asa.Theme.FlatPanel panParam;
protected Asa.Theme.FlatPanel panResult;
public ImageBoxEx aoiImage;
private Asa.Theme.FlatButton btnYuan;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cyotek.Windows.Forms;
using AOI;
using System.Drawing.Drawing2D;
namespace AccAOI.control
{
public partial class ABaseControl : Form
{
public ABaseControl()
{
InitializeComponent();
}
public string TitleName
{
get { return panControl.Text; }
set { panControl.Text = value; }
}
/// <summary>
/// 区域类型,1=矩形,2=圆形
/// </summary>
public int AreaType = 1;
/// <summary>
/// 区域信息
/// </summary>
public GraphicsPath currPath = null;
internal ImageBoxEx BImageBox;
internal AoiMethod AoiInfo;
public void SetImageBox(ImageBoxEx box)
{
this.BImageBox = box;
}
public void SeetAoiInfo(AoiMethod aoi)
{
this.AoiInfo = aoi;
}
public virtual void ShowAoiInfo()
{
}public virtual AoiMethod GetAoiInfo()
{
return AoiInfo;
}
private void btnSetArea_Click(object sender, EventArgs e)
{
AreaType = 1;
panAreaSet.Text = "区域设置-矩形";
}
private void btnYuan_Click(object sender, EventArgs e)
{
AreaType = 2;
panAreaSet.Text = "区域设置-椭圆";
}
private void btnClearArea_Click(object sender, EventArgs e)
{
this.BImageBox.CleearArea();
this.aoiImage.Image = null;
}
}
}
<?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
namespace AccAOI.control
{
partial class AioMarkControl
{
/// <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 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// panResult
//
this.panResult.Size = new System.Drawing.Size(298, 197);
//
// AioMarkControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(312, 700);
this.Name = "AioMarkControl";
this.TitleName = "Mark设置";
this.ResumeLayout(false);
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AOI;
namespace AccAOI.control
{
public partial class AioMarkControl : ABaseControl
{
public AioMarkControl()
{
InitializeComponent();
}
public override AoiMethod GetAoiInfo()
{
if (currPath != null)
{
this.AoiInfo.RoiPath = currPath;
}
return base.GetAoiInfo();
}
}
}
<?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
namespace AccAOI.control
{
partial class AoiBlobControl
{
/// <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 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.flatLabel1 = new Asa.Theme.FlatLabel();
this.trackBarThresh = new System.Windows.Forms.TrackBar();
this.lblthresh = new Asa.Theme.FlatLabel();
this.flatLabel3 = new Asa.Theme.FlatLabel();
this.chkwhiteOnBlack = new Asa.Theme.FlatCheck();
this.flatLabel2 = new Asa.Theme.FlatLabel();
this.txtminArea = new Asa.Theme.FlatText();
this.txtmaxArea = new Asa.Theme.FlatText();
this.flatLabel5 = new Asa.Theme.FlatLabel();
this.flatLabel4 = new Asa.Theme.FlatLabel();
this.txtmaxNum = new Asa.Theme.FlatText();
this.txtminNum = new Asa.Theme.FlatText();
this.flatLabel6 = new Asa.Theme.FlatLabel();
((System.ComponentModel.ISupportInitialize)(this.trackBarThresh)).BeginInit();
this.SuspendLayout();
//
// panParam
//
this.panParam.Location = new System.Drawing.Point(2, 319);
this.panParam.Size = new System.Drawing.Size(302, 146);
//
// panResult
//
this.panResult.Location = new System.Drawing.Point(2, 471);
this.panResult.Size = new System.Drawing.Size(302, 216);
//
// flatLabel1
//
this.flatLabel1.Inside = false;
this.flatLabel1.Location = new System.Drawing.Point(14, 358);
this.flatLabel1.Name = "flatLabel1";
this.flatLabel1.Size = new System.Drawing.Size(42, 30);
this.flatLabel1.TabIndex = 8;
this.flatLabel1.Text = "阈值:";
this.flatLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// trackBarThresh
//
this.trackBarThresh.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.trackBarThresh.Location = new System.Drawing.Point(63, 364);
this.trackBarThresh.Maximum = 255;
this.trackBarThresh.Minimum = -1;
this.trackBarThresh.Name = "trackBarThresh";
this.trackBarThresh.Size = new System.Drawing.Size(201, 45);
this.trackBarThresh.TabIndex = 9;
this.trackBarThresh.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBarThresh.Value = 100;
this.trackBarThresh.ValueChanged += new System.EventHandler(this.trackBarThresh_ValueChanged);
//
// lblthresh
//
this.lblthresh.Inside = false;
this.lblthresh.Location = new System.Drawing.Point(265, 358);
this.lblthresh.Name = "lblthresh";
this.lblthresh.Size = new System.Drawing.Size(30, 30);
this.lblthresh.TabIndex = 10;
this.lblthresh.Text = "100";
//
// flatLabel3
//
this.flatLabel3.Inside = false;
this.flatLabel3.Location = new System.Drawing.Point(14, 508);
this.flatLabel3.Name = "flatLabel3";
this.flatLabel3.Size = new System.Drawing.Size(75, 30);
this.flatLabel3.TabIndex = 13;
this.flatLabel3.Text = "面积过滤:";
//
// chkwhiteOnBlack
//
this.chkwhiteOnBlack.Inside = false;
this.chkwhiteOnBlack.Location = new System.Drawing.Point(151, 405);
this.chkwhiteOnBlack.Name = "chkwhiteOnBlack";
this.chkwhiteOnBlack.Size = new System.Drawing.Size(62, 30);
this.chkwhiteOnBlack.TabIndex = 15;
//
// flatLabel2
//
this.flatLabel2.Inside = false;
this.flatLabel2.Location = new System.Drawing.Point(14, 405);
this.flatLabel2.Name = "flatLabel2";
this.flatLabel2.Size = new System.Drawing.Size(75, 30);
this.flatLabel2.TabIndex = 16;
this.flatLabel2.Text = "图形反转:";
this.flatLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtminArea
//
this.txtminArea.Font = new System.Drawing.Font("宋体", 9F);
this.txtminArea.Inside = false;
this.txtminArea.Location = new System.Drawing.Point(98, 508);
this.txtminArea.Name = "txtminArea";
this.txtminArea.Padding = new System.Windows.Forms.Padding(3);
this.txtminArea.Size = new System.Drawing.Size(74, 30);
this.txtminArea.TabIndex = 17;
//
// txtmaxArea
//
this.txtmaxArea.Font = new System.Drawing.Font("宋体", 9F);
this.txtmaxArea.Inside = false;
this.txtmaxArea.Location = new System.Drawing.Point(205, 508);
this.txtmaxArea.Name = "txtmaxArea";
this.txtmaxArea.Padding = new System.Windows.Forms.Padding(3);
this.txtmaxArea.Size = new System.Drawing.Size(74, 30);
this.txtmaxArea.TabIndex = 18;
//
// flatLabel5
//
this.flatLabel5.Inside = false;
this.flatLabel5.Location = new System.Drawing.Point(176, 514);
this.flatLabel5.Name = "flatLabel5";
this.flatLabel5.Size = new System.Drawing.Size(24, 25);
this.flatLabel5.TabIndex = 19;
this.flatLabel5.Text = "~";
//
// flatLabel4
//
this.flatLabel4.Inside = false;
this.flatLabel4.Location = new System.Drawing.Point(176, 557);
this.flatLabel4.Name = "flatLabel4";
this.flatLabel4.Size = new System.Drawing.Size(24, 39);
this.flatLabel4.TabIndex = 23;
this.flatLabel4.Text = "~";
//
// txtmaxNum
//
this.txtmaxNum.Font = new System.Drawing.Font("宋体", 9F);
this.txtmaxNum.Inside = false;
this.txtmaxNum.Location = new System.Drawing.Point(205, 557);
this.txtmaxNum.Name = "txtmaxNum";
this.txtmaxNum.Padding = new System.Windows.Forms.Padding(3);
this.txtmaxNum.Size = new System.Drawing.Size(74, 30);
this.txtmaxNum.TabIndex = 22;
//
// txtminNum
//
this.txtminNum.Font = new System.Drawing.Font("宋体", 9F);
this.txtminNum.Inside = false;
this.txtminNum.Location = new System.Drawing.Point(98, 557);
this.txtminNum.Name = "txtminNum";
this.txtminNum.Padding = new System.Windows.Forms.Padding(3);
this.txtminNum.Size = new System.Drawing.Size(74, 30);
this.txtminNum.TabIndex = 21;
//
// flatLabel6
//
this.flatLabel6.Inside = false;
this.flatLabel6.Location = new System.Drawing.Point(14, 557);
this.flatLabel6.Name = "flatLabel6";
this.flatLabel6.Size = new System.Drawing.Size(75, 30);
this.flatLabel6.TabIndex = 20;
this.flatLabel6.Text = "数量判断:";
//
// AoiBlobControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(312, 699);
this.Controls.Add(this.flatLabel4);
this.Controls.Add(this.txtmaxNum);
this.Controls.Add(this.txtminNum);
this.Controls.Add(this.flatLabel6);
this.Controls.Add(this.flatLabel5);
this.Controls.Add(this.txtmaxArea);
this.Controls.Add(this.txtminArea);
this.Controls.Add(this.flatLabel2);
this.Controls.Add(this.chkwhiteOnBlack);
this.Controls.Add(this.flatLabel3);
this.Controls.Add(this.lblthresh);
this.Controls.Add(this.trackBarThresh);
this.Controls.Add(this.flatLabel1);
this.Name = "AoiBlobControl";
this.Controls.SetChildIndex(this.panParam, 0);
this.Controls.SetChildIndex(this.panResult, 0);
this.Controls.SetChildIndex(this.flatLabel1, 0);
this.Controls.SetChildIndex(this.trackBarThresh, 0);
this.Controls.SetChildIndex(this.lblthresh, 0);
this.Controls.SetChildIndex(this.flatLabel3, 0);
this.Controls.SetChildIndex(this.chkwhiteOnBlack, 0);
this.Controls.SetChildIndex(this.flatLabel2, 0);
this.Controls.SetChildIndex(this.txtminArea, 0);
this.Controls.SetChildIndex(this.txtmaxArea, 0);
this.Controls.SetChildIndex(this.flatLabel5, 0);
this.Controls.SetChildIndex(this.flatLabel6, 0);
this.Controls.SetChildIndex(this.txtminNum, 0);
this.Controls.SetChildIndex(this.txtmaxNum, 0);
this.Controls.SetChildIndex(this.flatLabel4, 0);
((System.ComponentModel.ISupportInitialize)(this.trackBarThresh)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Asa.Theme.FlatLabel flatLabel1;
private System.Windows.Forms.TrackBar trackBarThresh;
private Asa.Theme.FlatLabel lblthresh;
private Asa.Theme.FlatLabel flatLabel3;
private Asa.Theme.FlatCheck chkwhiteOnBlack;
private Asa.Theme.FlatLabel flatLabel2;
private Asa.Theme.FlatText txtminArea;
private Asa.Theme.FlatText txtmaxArea;
private Asa.Theme.FlatLabel flatLabel5;
private Asa.Theme.FlatLabel flatLabel4;
private Asa.Theme.FlatText txtmaxNum;
private Asa.Theme.FlatText txtminNum;
private Asa.Theme.FlatLabel flatLabel6;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AOI;
namespace AccAOI.control
{
public partial class AoiBlobControl : ABaseControl
{
public AoiBlobControl()
{
InitializeComponent();
}
private void trackBarThresh_ValueChanged(object sender, EventArgs e)
{
int value = trackBarThresh.Value;
lblthresh.Text = value.ToString();
}
public override void ShowAoiInfo()
{
if(this.AoiInfo is AoiBlobMethod)
{
AoiBlobMethod aInfo = (AoiBlobMethod)AoiInfo;
if (aInfo.thresh < 0)
{
trackBarThresh.Value = 0;
}
else
{
trackBarThresh.Value = aInfo.thresh;
}
chkwhiteOnBlack.Checked = aInfo.whiteOnBlack;
txtmaxArea.Text = aInfo.maxArea.ToString();
txtminArea.Text = aInfo.minArea.ToString();
txtmaxNum.Text = aInfo.maxNum.ToString();
txtminNum.Text = aInfo.minNum.ToString();
}
}
public override AoiMethod GetAoiInfo()
{
if (this.AoiInfo is AoiBlobMethod)
{
AoiBlobMethod aInfo = (AoiBlobMethod)AoiInfo;
if (trackBarThresh.Value.Equals(0))
{
aInfo.thresh = -1;
}
else
{
aInfo.thresh= trackBarThresh.Value;
}
aInfo.whiteOnBlack= chkwhiteOnBlack.Checked ;
aInfo.maxArea = FormUtil.GetIntValue(txtmaxArea);
aInfo.minArea = FormUtil.GetIntValue(txtminArea);
aInfo.maxNum = FormUtil.GetIntValue(txtmaxNum);
aInfo.minNum = FormUtil.GetIntValue(txtminNum);
if (currPath != null)
{
aInfo.RoiPath = currPath;
}
}
return AoiInfo;
}
}
}
<?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
namespace AccAOI.control
{
partial class AoiRgbControl
{
/// <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 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.flatLabel5 = new Asa.Theme.FlatLabel();
this.txtmaxRate = new Asa.Theme.FlatText();
this.txtminRate = new Asa.Theme.FlatText();
this.flatLabel3 = new Asa.Theme.FlatLabel();
this.flatLabel1 = new Asa.Theme.FlatLabel();
this.txtMaxR = new Asa.Theme.FlatText();
this.txtMinR = new Asa.Theme.FlatText();
this.flatLabel2 = new Asa.Theme.FlatLabel();
this.flatLabel4 = new Asa.Theme.FlatLabel();
this.txtMaxG = new Asa.Theme.FlatText();
this.txtMinG = new Asa.Theme.FlatText();
this.flatLabel6 = new Asa.Theme.FlatLabel();
this.flatLabel7 = new Asa.Theme.FlatLabel();
this.txtMaxB = new Asa.Theme.FlatText();
this.txtMinB = new Asa.Theme.FlatText();
this.flatLabel8 = new Asa.Theme.FlatLabel();
this.SuspendLayout();
//
// panParam
//
this.panParam.Size = new System.Drawing.Size(291, 166);
//
// panResult
//
this.panResult.Size = new System.Drawing.Size(291, 189);
//
// flatLabel5
//
this.flatLabel5.Inside = false;
this.flatLabel5.Location = new System.Drawing.Point(181, 533);
this.flatLabel5.Name = "flatLabel5";
this.flatLabel5.Size = new System.Drawing.Size(24, 25);
this.flatLabel5.TabIndex = 23;
this.flatLabel5.Text = "~";
//
// txtmaxRate
//
this.txtmaxRate.Font = new System.Drawing.Font("宋体", 9F);
this.txtmaxRate.Inside = false;
this.txtmaxRate.Location = new System.Drawing.Point(210, 527);
this.txtmaxRate.Name = "txtmaxRate";
this.txtmaxRate.Padding = new System.Windows.Forms.Padding(3);
this.txtmaxRate.Size = new System.Drawing.Size(74, 30);
this.txtmaxRate.TabIndex = 22;
//
// txtminRate
//
this.txtminRate.Font = new System.Drawing.Font("宋体", 9F);
this.txtminRate.Inside = false;
this.txtminRate.Location = new System.Drawing.Point(103, 527);
this.txtminRate.Name = "txtminRate";
this.txtminRate.Padding = new System.Windows.Forms.Padding(3);
this.txtminRate.Size = new System.Drawing.Size(74, 30);
this.txtminRate.TabIndex = 21;
//
// flatLabel3
//
this.flatLabel3.Inside = false;
this.flatLabel3.Location = new System.Drawing.Point(19, 527);
this.flatLabel3.Name = "flatLabel3";
this.flatLabel3.Size = new System.Drawing.Size(75, 30);
this.flatLabel3.TabIndex = 20;
this.flatLabel3.Text = "像素占比:";
//
// flatLabel1
//
this.flatLabel1.Inside = false;
this.flatLabel1.Location = new System.Drawing.Point(181, 358);
this.flatLabel1.Name = "flatLabel1";
this.flatLabel1.Size = new System.Drawing.Size(24, 25);
this.flatLabel1.TabIndex = 27;
this.flatLabel1.Text = "~";
//
// txtMaxR
//
this.txtMaxR.Font = new System.Drawing.Font("宋体", 9F);
this.txtMaxR.Inside = false;
this.txtMaxR.Location = new System.Drawing.Point(210, 352);
this.txtMaxR.Name = "txtMaxR";
this.txtMaxR.Padding = new System.Windows.Forms.Padding(3);
this.txtMaxR.Size = new System.Drawing.Size(74, 30);
this.txtMaxR.TabIndex = 26;
//
// txtMinR
//
this.txtMinR.Font = new System.Drawing.Font("宋体", 9F);
this.txtMinR.Inside = false;
this.txtMinR.Location = new System.Drawing.Point(103, 352);
this.txtMinR.Name = "txtMinR";
this.txtMinR.Padding = new System.Windows.Forms.Padding(3);
this.txtMinR.Size = new System.Drawing.Size(74, 30);
this.txtMinR.TabIndex = 25;
//
// flatLabel2
//
this.flatLabel2.Inside = false;
this.flatLabel2.Location = new System.Drawing.Point(19, 352);
this.flatLabel2.Name = "flatLabel2";
this.flatLabel2.Size = new System.Drawing.Size(75, 30);
this.flatLabel2.TabIndex = 24;
this.flatLabel2.Text = "R:";
//
// flatLabel4
//
this.flatLabel4.Inside = false;
this.flatLabel4.Location = new System.Drawing.Point(181, 404);
this.flatLabel4.Name = "flatLabel4";
this.flatLabel4.Size = new System.Drawing.Size(24, 25);
this.flatLabel4.TabIndex = 31;
this.flatLabel4.Text = "~";
//
// txtMaxG
//
this.txtMaxG.Font = new System.Drawing.Font("宋体", 9F);
this.txtMaxG.Inside = false;
this.txtMaxG.Location = new System.Drawing.Point(210, 398);
this.txtMaxG.Name = "txtMaxG";
this.txtMaxG.Padding = new System.Windows.Forms.Padding(3);
this.txtMaxG.Size = new System.Drawing.Size(74, 30);
this.txtMaxG.TabIndex = 30;
//
// txtMinG
//
this.txtMinG.Font = new System.Drawing.Font("宋体", 9F);
this.txtMinG.Inside = false;
this.txtMinG.Location = new System.Drawing.Point(103, 398);
this.txtMinG.Name = "txtMinG";
this.txtMinG.Padding = new System.Windows.Forms.Padding(3);
this.txtMinG.Size = new System.Drawing.Size(74, 30);
this.txtMinG.TabIndex = 29;
//
// flatLabel6
//
this.flatLabel6.Inside = false;
this.flatLabel6.Location = new System.Drawing.Point(19, 398);
this.flatLabel6.Name = "flatLabel6";
this.flatLabel6.Size = new System.Drawing.Size(75, 30);
this.flatLabel6.TabIndex = 28;
this.flatLabel6.Text = "G:";
//
// flatLabel7
//
this.flatLabel7.Inside = false;
this.flatLabel7.Location = new System.Drawing.Point(181, 450);
this.flatLabel7.Name = "flatLabel7";
this.flatLabel7.Size = new System.Drawing.Size(24, 25);
this.flatLabel7.TabIndex = 35;
this.flatLabel7.Text = "~";
//
// txtMaxB
//
this.txtMaxB.Font = new System.Drawing.Font("宋体", 9F);
this.txtMaxB.Inside = false;
this.txtMaxB.Location = new System.Drawing.Point(210, 444);
this.txtMaxB.Name = "txtMaxB";
this.txtMaxB.Padding = new System.Windows.Forms.Padding(3);
this.txtMaxB.Size = new System.Drawing.Size(74, 30);
this.txtMaxB.TabIndex = 34;
//
// txtMinB
//
this.txtMinB.Font = new System.Drawing.Font("宋体", 9F);
this.txtMinB.Inside = false;
this.txtMinB.Location = new System.Drawing.Point(103, 444);
this.txtMinB.Name = "txtMinB";
this.txtMinB.Padding = new System.Windows.Forms.Padding(3);
this.txtMinB.Size = new System.Drawing.Size(74, 30);
this.txtMinB.TabIndex = 33;
//
// flatLabel8
//
this.flatLabel8.Inside = false;
this.flatLabel8.Location = new System.Drawing.Point(19, 444);
this.flatLabel8.Name = "flatLabel8";
this.flatLabel8.Size = new System.Drawing.Size(75, 30);
this.flatLabel8.TabIndex = 32;
this.flatLabel8.Text = "B:";
//
// AoiRgbControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(312, 700);
this.Controls.Add(this.flatLabel7);
this.Controls.Add(this.txtMaxB);
this.Controls.Add(this.txtMinB);
this.Controls.Add(this.flatLabel8);
this.Controls.Add(this.flatLabel4);
this.Controls.Add(this.txtMaxG);
this.Controls.Add(this.txtMinG);
this.Controls.Add(this.flatLabel6);
this.Controls.Add(this.flatLabel1);
this.Controls.Add(this.txtMaxR);
this.Controls.Add(this.txtMinR);
this.Controls.Add(this.flatLabel2);
this.Controls.Add(this.flatLabel5);
this.Controls.Add(this.txtmaxRate);
this.Controls.Add(this.txtminRate);
this.Controls.Add(this.flatLabel3);
this.Name = "AoiRgbControl";
this.TitleName = "颜色抽取";
this.Controls.SetChildIndex(this.panParam, 0);
this.Controls.SetChildIndex(this.panResult, 0);
this.Controls.SetChildIndex(this.flatLabel3, 0);
this.Controls.SetChildIndex(this.txtminRate, 0);
this.Controls.SetChildIndex(this.txtmaxRate, 0);
this.Controls.SetChildIndex(this.flatLabel5, 0);
this.Controls.SetChildIndex(this.flatLabel2, 0);
this.Controls.SetChildIndex(this.txtMinR, 0);
this.Controls.SetChildIndex(this.txtMaxR, 0);
this.Controls.SetChildIndex(this.flatLabel1, 0);
this.Controls.SetChildIndex(this.flatLabel6, 0);
this.Controls.SetChildIndex(this.txtMinG, 0);
this.Controls.SetChildIndex(this.txtMaxG, 0);
this.Controls.SetChildIndex(this.flatLabel4, 0);
this.Controls.SetChildIndex(this.flatLabel8, 0);
this.Controls.SetChildIndex(this.txtMinB, 0);
this.Controls.SetChildIndex(this.txtMaxB, 0);
this.Controls.SetChildIndex(this.flatLabel7, 0);
this.ResumeLayout(false);
}
#endregion
private Asa.Theme.FlatLabel flatLabel5;
private Asa.Theme.FlatText txtmaxRate;
private Asa.Theme.FlatText txtminRate;
private Asa.Theme.FlatLabel flatLabel3;
private Asa.Theme.FlatLabel flatLabel1;
private Asa.Theme.FlatText txtMaxR;
private Asa.Theme.FlatText txtMinR;
private Asa.Theme.FlatLabel flatLabel2;
private Asa.Theme.FlatLabel flatLabel4;
private Asa.Theme.FlatText txtMaxG;
private Asa.Theme.FlatText txtMinG;
private Asa.Theme.FlatLabel flatLabel6;
private Asa.Theme.FlatLabel flatLabel7;
private Asa.Theme.FlatText txtMaxB;
private Asa.Theme.FlatText txtMinB;
private Asa.Theme.FlatLabel flatLabel8;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AOI;
namespace AccAOI.control
{
public partial class AoiRgbControl : ABaseControl
{
public AoiRgbControl()
{
InitializeComponent();
}
public override void ShowAoiInfo()
{
if (this.AoiInfo is AoiMethodRgb)
{
AoiMethodRgb aInfo = (AoiMethodRgb)AoiInfo;
txtMinR.Text = aInfo.minR.ToString();
txtMaxR.Text = aInfo.maxR.ToString();
txtMinG.Text = aInfo.minG.ToString();
txtMaxG.Text = aInfo.maxG.ToString();
txtMaxB.Text = aInfo.maxB.ToString();
txtMinB.Text = aInfo.minB.ToString();
txtminRate.Text = aInfo.minRate.ToString();
txtmaxRate.Text = aInfo.maxRate.ToString();
}
}
public override AoiMethod GetAoiInfo()
{
if (this.AoiInfo is AoiMethodRgb)
{
AoiMethodRgb aInfo = (AoiMethodRgb)AoiInfo;
aInfo.minR = FormUtil.GetIntValue(txtMinR);
aInfo.maxR = FormUtil.GetIntValue(txtMaxR);
aInfo.minG = FormUtil.GetIntValue(txtMinG);
aInfo.maxG = FormUtil.GetIntValue(txtMaxG);
aInfo.maxB = FormUtil.GetIntValue(txtMaxB);
aInfo.minB = FormUtil.GetIntValue(txtMinB);
aInfo.minRate = FormUtil.GetIntValue(txtminRate);
aInfo.maxRate = FormUtil.GetIntValue(txtmaxRate);
if (currPath != null)
{
aInfo.RoiPath = currPath;
}
}
return AoiInfo;
}
}
}
<?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
......@@ -2,16 +2,16 @@
namespace AccAOI
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// http://cyotek.com
// http://cyotek.com/blog/tag/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.
// Licensed under the MIT License. See imagebox-license.txt for the full text.
// If you use this control in your applications, attribution, donations or contributions are welcome.
// If you use this control in your applications, attribution, donations or contributions are welcome.
internal class DragHandle
public class DragHandle
{
#region Public Constructors
......
namespace AccAOI
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// http://cyotek.com
// http://cyotek.com/blog/tag/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.
// Licensed under the MIT License. See imagebox-license.txt for the full text.
// If you use this control in your applications, attribution, donations or contributions are welcome.
// If you use this control in your applications, attribution, donations or contributions are welcome.
internal enum DragHandleAnchor
public enum DragHandleAnchor
{
None,
......
......@@ -4,16 +4,16 @@ using System.Drawing;
namespace AccAOI
{
// Cyotek ImageBox
// Copyright (c) 2010-2014 Cyotek.
// http://cyotek.com
// http://cyotek.com/blog/tag/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.
// Licensed under the MIT License. See imagebox-license.txt for the full text.
// If you use this control in your applications, attribution, donations or contributions are welcome.
// If you use this control in your applications, attribution, donations or contributions are welcome.
internal class DragHandleCollection : IEnumerable<DragHandle>
public class DragHandleCollection : IEnumerable<DragHandle>
{
#region Instance Fields
......
//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.
// internal class ImageBoxEx : ImageBox
// {
// #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;
using Cyotek.Windows.Forms;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
// anchor = this.HitTest(this.DragOrigin);
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
// }
//}
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
}
}
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!