DHDHSoftware/DHSoftware/Views/UserDetetion.cs

227 lines
7.2 KiB
C#
Raw Permalink Normal View History

2025-03-13 18:54:05 +08:00
using AntdUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
2025-03-15 09:47:09 +08:00
using Button = AntdUI.Button;
2025-03-13 18:54:05 +08:00
namespace DHSoftware.Views
{
public partial class UserDetetion : UserControl
{
2025-03-15 09:47:09 +08:00
private StackPanel panel, panel2, panel3, panel4;
public Window _windows;
2025-03-13 18:54:05 +08:00
//根据检测配置 将对应的相机配置、中处理预处理、尺寸测量
2025-03-16 13:11:08 +08:00
public UserDetetion(Window windows,int parentWidth, int parentHeight)
2025-03-13 18:54:05 +08:00
{
InitializeComponent();
2025-03-16 13:11:08 +08:00
_windows = windows;
2025-03-13 18:54:05 +08:00
AntdUI.CollapseItem group1 = new CollapseItem();
2025-03-15 09:47:09 +08:00
group1.Height = parentHeight / 4;
2025-03-13 18:54:05 +08:00
group1.Text = "相机配置";
AntdUI.CollapseItem group2 = new CollapseItem();
2025-03-15 09:47:09 +08:00
group2.Text = "预处理";
group2.Height = parentHeight/4;
2025-03-13 18:54:05 +08:00
AntdUI.CollapseItem group3 = new CollapseItem();
2025-03-15 09:47:09 +08:00
group3.Text = "中处理";
group3.Height = parentHeight - 300;
2025-03-13 18:54:05 +08:00
2025-03-15 09:47:09 +08:00
AntdUI.CollapseItem group4 = new CollapseItem();
group4.Text = "尺寸测量";
group4.Height = parentHeight / 4;
2025-03-13 18:54:05 +08:00
2025-03-15 09:47:09 +08:00
// 初始化内容面板
panel = CreateScrollPanel();
panel2 = CreateScrollPanel();
panel3 = CreateScrollPanel();
panel4 = CreateScrollPanel();
2025-03-13 18:54:05 +08:00
2025-03-15 09:47:09 +08:00
// 添加预处理控件
var ptuc = new PreTreatUserControl { AutoScroll = true, Dock = DockStyle.Top };
var detect = new DetectConfigControl { AutoScroll = true , Dock = DockStyle.Fill };
detect._window = this._windows;
2025-03-13 18:54:05 +08:00
2025-03-15 09:47:09 +08:00
// 添加尺寸测量控件
var sizeFrm = new SizeConfigControl();
2025-03-13 18:54:05 +08:00
CameraConfigControl camConfigFrm = new CameraConfigControl();
camConfigFrm.Dock = DockStyle.Fill;
2025-03-15 09:47:09 +08:00
//PreTreatUserControl ptuc = new PreTreatUserControl();
//ptuc.AutoScroll = true;
//panel2.Controls.Add(ptuc);
//DetectConfigControl detect = new DetectConfigControl();
//// detect.Dock = DockStyle.Fill;
//detect.AutoScroll = true;
//panel2.Controls.Add(detect);
2025-03-13 18:54:05 +08:00
2025-03-15 09:47:09 +08:00
//SizeConfigControl Sizefc = new SizeConfigControl();
//Sizefc.Dock = DockStyle.Fill;
//panel3.Controls.Add(Sizefc);
2025-03-13 18:54:05 +08:00
2025-03-15 09:47:09 +08:00
Button btnAddCam = new Button
{
Width = 100,
Height = 30,
Text = "添加相机配置",
//Dock=DockStyle.Bottom
};
Button btnDelCam = new Button
{
Width = 100,
Height = 30,
Text = "删除相机配置",
// Dock = DockStyle.Bottom
};
Button btnAddModel = new Button
{
Width = 100,
Height = 30,
Text = "添加模型配置",
//Dock=DockStyle.Bottom
};
Button btnDelModel = new Button
{
Width = 100,
Height = 30,
Text = "删除模型配置",
// Dock = DockStyle.Bottom
};
FlowLayoutPanel flow = new FlowLayoutPanel();
flow.Dock = DockStyle.Bottom;
flow.Controls.Add(btnAddCam);
flow.Controls.Add(btnDelCam);
FlowLayoutPanel flowmodel = new FlowLayoutPanel();
flowmodel.Dock = DockStyle.Bottom;
flowmodel.Controls.Add(btnAddModel);
flowmodel.Controls.Add(btnDelModel);
btnAddCam.Click += btnAddCam_Click;
btnDelCam.Click += btnDelCam_Click;
btnAddModel.Click += btnAddModel_Click;
btnDelModel.Click += btnDelModel_Click;
panel.Controls.Add(flow);
panel.Controls.Add(camConfigFrm);
panel2.Controls.Add(ptuc);
panel3.Controls.Add(flowmodel);
panel3.Controls.Add(detect);
panel4.Controls.Add(sizeFrm);
2025-03-13 18:54:05 +08:00
group1.Controls.Add(panel);
group2.Controls.Add(panel2);
group3.Controls.Add(panel3);
2025-03-15 09:47:09 +08:00
group4.Controls.Add(panel4);
2025-03-13 18:54:05 +08:00
//collapse1.Items.Add(group1);
collapse1.Items.Add(group1);
collapse1.Items.Add(group2);
collapse1.Items.Add(group3);
2025-03-15 09:47:09 +08:00
collapse1.Items.Add(group4);
2025-03-13 18:54:05 +08:00
}
2025-03-15 09:47:09 +08:00
// 统一事件处理
private void CameraOperation_Click(object sender, EventArgs e)
{
if (sender is Button btn)
{
switch (btn.Tag?.ToString())
{
case "Add":
AddCameraConfig();
break;
case "Delete":
DeleteCameraConfig();
break;
}
}
}
// 实际业务方法
private void AddCameraConfig()
{
var newCamConfig = new CameraConfigControl { Dock = DockStyle.Top };
panel.Controls.Add(newCamConfig);
panel.ScrollControlIntoView(newCamConfig);
}
private void DeleteCameraConfig()
{
if (panel.Controls.Count > 1)
{
panel.Controls.RemoveAt(panel.Controls.Count - 2);
}
}
// 创建带滚动条的面板
private StackPanel CreateScrollPanel()
{
return new StackPanel
{
Dock = DockStyle.Fill,
Vertical = true,
AutoScroll = true,
Padding = new Padding(5) // 添加内边距避免内容贴边
};
}
private void btnAddCam_Click(object sender, EventArgs e)
{
CameraConfigControl camConfigFrm2 = new CameraConfigControl();
camConfigFrm2.Dock = DockStyle.Fill;
panel.Controls.Add(camConfigFrm2);
}
private void btnDelCam_Click(object sender, EventArgs e)
{
// 遍历 panel 的 Controls找到最后一个 CameraConfigControl 并移除
for (int i = panel.Controls.Count - 1; i >= 0; i--)
{
if (panel.Controls[i] is CameraConfigControl)
{
panel.Controls.RemoveAt(i);
break; // 只删除一个
}
}
}
private void btnAddModel_Click(object sender, EventArgs e)
{
DetectConfigControl DetectFrm = new DetectConfigControl();
DetectFrm._window = this._windows;
DetectFrm.Dock = DockStyle.Fill;
panel3.Controls.Add(DetectFrm);
}
private void btnDelModel_Click(object sender, EventArgs e)
{
// 遍历 panel 的 Controls找到最后一个 CameraConfigControl 并移除
for (int i = panel3.Controls.Count - 1; i >= 0; i--)
{
2025-03-16 13:11:08 +08:00
if (panel3.Controls[i] is DetectConfigControl)
2025-03-15 09:47:09 +08:00
{
panel3.Controls.RemoveAt(i);
break; // 只删除一个
}
}
}
2025-03-13 18:54:05 +08:00
}
}