CanFly
CanFly.Canvas
DH.Commons
DH.Commons.Devies
DH.Devices.Camera
DH.Devices.Motion
DH.Devices.PLC
DH.Devices.Vision
DH.UI.Model.Winform
DHSoftware
Languages
Models
Properties
Resources
Services
Utils
Views
AddCameraControl.Designer.cs
AddCameraControl.cs
AddCameraControl.resx
AddCubicleControl.Designer.cs
AddCubicleControl.cs
AddCubicleControl.resx
AddMotionControl.Designer.cs
AddMotionControl.cs
AddMotionControl.resx
AddSchemeControl.Designer.cs
AddSchemeControl.cs
AddSchemeControl.resx
CamConfigFrm.Designer.cs
CamConfigFrm.cs
CamConfigFrm.resx
CameraConfigControl.Designer.cs
CameraConfigControl.cs
CameraConfigControl.resx
CameraControl.Designer.cs
CameraControl.cs
CameraControl.resx
CloseWindow.Designer.cs
CloseWindow.cs
CloseWindow.resx
CorrelatedCameraEdit.Designer.cs
CorrelatedCameraEdit.cs
CorrelatedCameraEdit.resx
CtrlVisionDisplay.Designer.cs
CtrlVisionDisplay.cs
CtrlVisionDisplay.resx
CtrlVisionRunBase.Designer.cs
CtrlVisionRunBase.cs
CtrlVisionRunBase.resx
DefectRowEdit.Designer.cs
DefectRowEdit.cs
DefectRowEdit.resx
DetectConfigControl.Designer.cs
DetectConfigControl.cs
DetectConfigControl.resx
DetectControl.Designer.cs
DetectControl.cs
DetectControl.resx
DetectionLableEdit.Designer.cs
DetectionLableEdit.cs
DetectionLableEdit.resx
MotionControl.Designer.cs
MotionControl.cs
MotionControl.resx
MotionEdit.Designer.cs
MotionEdit.cs
MotionEdit.resx
PreTreatEdit.Designer.cs
PreTreatEdit.cs
PreTreatEdit.resx
PreTreatUserControl.Designer.cs
PreTreatUserControl.cs
PreTreatUserControl.resx
SettingWindow.Designer.cs
SettingWindow.cs
SettingWindow.resx
SizeConfigControl.Designer.cs
SizeConfigControl.cs
SizeConfigControl.resx
SizeLabelEdit.Designer.cs
SizeLabelEdit.cs
SizeLabelEdit.resx
UserConfigFrm.Designer.cs
UserConfigFrm.cs
UserConfigFrm.resx
UserDetetion.Designer.cs
UserDetetion.cs
UserDetetion.resx
WelcomeWindow.Designer.cs
WelcomeWindow.cs
WelcomeWindow.resx
assets
App.config
DHSoftware.csproj
LICENSE
LoginWindow.Designer.cs
LoginWindow.cs
LoginWindow.resx
MainWindow.Designer.cs
MainWindow.cs
MainWindow.resx
Program.cs
app.manifest
productModel.cs
.gitignore
DHSoftware.sln
README.md
124 lines
4.0 KiB
C#
124 lines
4.0 KiB
C#
|
||
|
||
using System.ComponentModel;
|
||
using System.Reflection;
|
||
using AntdUI;
|
||
using DH.Commons.Base;
|
||
using DH.Devices.Vision;
|
||
|
||
namespace DHSoftware.Views
|
||
{
|
||
public partial class CorrelatedCameraEdit : UserControl
|
||
{
|
||
List<KeyValuePair<string, int>> resultStates = GetFilteredEnumDescriptionsAndValuesres<ResultState>();
|
||
|
||
// 获取枚举的描述和对应的值,只筛选出 OK 和 NG
|
||
public static List<KeyValuePair<string, int>> GetFilteredEnumDescriptionsAndValuesres<T>() where T : Enum
|
||
{
|
||
return Enum.GetValues(typeof(T))
|
||
.Cast<T>()
|
||
/* .Where(e => e.Equals(ResultState.OK) || e.Equals(ResultState.DetectNG))*/ // 只保留 OK 和 NG
|
||
.Select(e =>
|
||
{
|
||
// 通过反射获取 DescriptionAttribute 描述,如果没有描述,则使用枚举项名称
|
||
var description = e.GetType()
|
||
.GetField(e.ToString())
|
||
?.GetCustomAttribute<DescriptionAttribute>()
|
||
?.Description ?? e.ToString(); // 如果没有 DescriptionAttribute,则使用枚举名称
|
||
|
||
// 返回描述和值的键值对
|
||
return new KeyValuePair<string, int>(description, Convert.ToInt32(e));
|
||
})
|
||
.ToList();
|
||
}
|
||
private AntdUI.Window window;
|
||
private List<RelatedCamera> Cameras;
|
||
public bool submit;
|
||
public CorrelatedCameraEdit(AntdUI.Window _window, List<RelatedCamera> cameras)
|
||
{
|
||
this.window = _window;
|
||
Cameras = cameras;
|
||
InitializeComponent();
|
||
//设置默认值
|
||
InitData();
|
||
// 绑定事件
|
||
BindEventHandler();
|
||
}
|
||
|
||
private void BindEventHandler()
|
||
{
|
||
button_ok.Click += Button_ok_Click;
|
||
button_cancel.Click += Button_cancel_Click;
|
||
}
|
||
|
||
private void Button_cancel_Click(object sender, EventArgs e)
|
||
{
|
||
submit = false;
|
||
this.Dispose();
|
||
}
|
||
|
||
private void Button_ok_Click(object sender, EventArgs e)
|
||
{
|
||
if (flowPanel1.Controls.Count > 0)
|
||
{
|
||
Cameras.Clear();
|
||
foreach (Control control in flowPanel1.Controls)
|
||
{
|
||
if (control is AntdUI.Checkbox checkbox)
|
||
{
|
||
// 操作 CheckBox
|
||
bool isChecked = checkbox.Checked;
|
||
if (isChecked)
|
||
{
|
||
string name = checkbox.Text;
|
||
RelatedCamera relatedCamera = new RelatedCamera(name);
|
||
Cameras.Add(relatedCamera);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
submit = true;
|
||
this.Dispose();
|
||
}
|
||
|
||
private void InitData()
|
||
{
|
||
|
||
|
||
|
||
for (int i = 1; i < 15; i++)
|
||
{
|
||
string name = $"Cam{i}";
|
||
var control = new AntdUI.Checkbox()
|
||
{
|
||
AutoCheck = true,
|
||
Font = new System.Drawing.Font("Microsoft YaHei UI", 9F),
|
||
Size = new Size(90, 42),
|
||
Text = name,
|
||
ForeColor = Color.FromArgb(61, 94, 218)
|
||
};
|
||
foreach (var item in Cameras)
|
||
{
|
||
if (item.CameraSourceId.Equals(name))
|
||
{
|
||
control.Checked = true;
|
||
break;
|
||
}
|
||
}
|
||
// 通过主窗口设置DPI控制添加控件保持缩放比例
|
||
window.AutoDpi(control);
|
||
flowPanel1.Controls.Add(control);
|
||
control.BringToFront();
|
||
}
|
||
|
||
}
|
||
|
||
private void CorrelatedCameraEdit_Load(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|