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; using Button = AntdUI.Button; namespace DHSoftware.Views { public partial class UserDetetion : UserControl { private StackPanel panel, panel2, panel3, panel4; public Window _windows; //根据检测配置 将对应的相机配置、中处理预处理、尺寸测量 public UserDetetion(Window windows,int parentWidth, int parentHeight) { InitializeComponent(); _windows = windows; AntdUI.CollapseItem group1 = new CollapseItem(); group1.Height = parentHeight / 4; group1.Text = "相机配置"; AntdUI.CollapseItem group2 = new CollapseItem(); group2.Text = "预处理"; group2.Height = parentHeight/4; AntdUI.CollapseItem group3 = new CollapseItem(); group3.Text = "中处理"; group3.Height = parentHeight - 300; AntdUI.CollapseItem group4 = new CollapseItem(); group4.Text = "尺寸测量"; group4.Height = parentHeight / 4; // 初始化内容面板 panel = CreateScrollPanel(); panel2 = CreateScrollPanel(); panel3 = CreateScrollPanel(); panel4 = CreateScrollPanel(); // 添加预处理控件 var ptuc = new PreTreatUserControl { AutoScroll = true, Dock = DockStyle.Top }; var detect = new DetectConfigControl { AutoScroll = true , Dock = DockStyle.Fill }; detect._window = this._windows; // 添加尺寸测量控件 var sizeFrm = new SizeConfigControl(); CameraConfigControl camConfigFrm = new CameraConfigControl(); camConfigFrm.Dock = DockStyle.Fill; //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); //SizeConfigControl Sizefc = new SizeConfigControl(); //Sizefc.Dock = DockStyle.Fill; //panel3.Controls.Add(Sizefc); 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); group1.Controls.Add(panel); group2.Controls.Add(panel2); group3.Controls.Add(panel3); group4.Controls.Add(panel4); //collapse1.Items.Add(group1); collapse1.Items.Add(group1); collapse1.Items.Add(group2); collapse1.Items.Add(group3); collapse1.Items.Add(group4); } // 统一事件处理 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--) { if (panel3.Controls[i] is DetectConfigControl) { panel3.Controls.RemoveAt(i); break; // 只删除一个 } } } } }