界面优化
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
using AntdUI;
|
||||
using AntdUIDemo.Models;
|
||||
using AntdUIDemo.Views;
|
||||
using DH.Devices.Devices;
|
||||
using DH.Devices.Vision;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -11,17 +12,21 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using Window = AntdUI.Window;
|
||||
|
||||
namespace DHSoftware.Views
|
||||
{
|
||||
public partial class UserConfigFrm : UserControl
|
||||
{
|
||||
public List<CameraBase> cameras = new List<CameraBase>();
|
||||
public List<DetectionConfig> detections = new List<DetectionConfig>();
|
||||
private UserControl currControl;
|
||||
private bool isUpdatingTabs = false;//用于阻止Tabs更新
|
||||
public Window Window;
|
||||
public UserConfigFrm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
LoadMenu();
|
||||
menu.Width = (int)(100 * Config.Dpi);
|
||||
|
||||
@ -104,15 +109,79 @@ namespace DHSoftware.Views
|
||||
}
|
||||
menu.SelectIndex(rootIndex, subIndex, true);
|
||||
}
|
||||
private void Menu_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
// 转换坐标到控件内部坐标系(考虑滚动条)
|
||||
Point clickPoint = new Point(e.X, e.Y + menu.ScrollBar.Value);
|
||||
|
||||
// 递归查找命中的菜单项
|
||||
MenuItem clickedItem = FindClickedItem(menu.Items, clickPoint);
|
||||
|
||||
if (clickedItem != null)
|
||||
{
|
||||
// 显示节点名称弹窗
|
||||
//MessageBox.Show($"右键点击的节点: {clickedItem.Text}");
|
||||
|
||||
var menulist = new AntdUI.IContextMenuStripItem[]
|
||||
{
|
||||
new AntdUI.ContextMenuStripItem("关联相机", "")
|
||||
{
|
||||
IconSvg = "VideoCameraAddOutlined"
|
||||
}
|
||||
};
|
||||
AntdUI.ContextMenuStrip.open(menu, it =>
|
||||
{
|
||||
if (it.Text == "关联相机")
|
||||
{
|
||||
using (var dlg = new AddCameraWindow(cameras))
|
||||
{
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
var newItem = new MenuItem(dlg.CubicleName);
|
||||
newItem.IconSvg = "VideoCameraOutlined";
|
||||
//// 防止重复添加
|
||||
//if (!menu1.Items.Cast<MenuItem>().Any(m => m.Text == newItem.Text))
|
||||
//{
|
||||
clickedItem.Sub.Add(newItem);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// AntdUI.Notification.warn(this, "新增失败", $"{dlg.CubicleName}已存在!", autoClose: 3, align: TAlignFrom.TR);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, menulist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MenuItem FindClickedItem(MenuItemCollection items, Point clickPoint)
|
||||
{
|
||||
foreach (MenuItem item in items)
|
||||
{
|
||||
// 检查当前项是否可见且包含点击坐标
|
||||
if (item.Visible && item.Rect.Contains(clickPoint))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void Menu_SelectChanged(object sender, MenuSelectEventArgs e)
|
||||
{
|
||||
string name = (string)e.Value.Tag;
|
||||
|
||||
// 清理上一个浮动按钮窗体
|
||||
if (currControl is FloatButtonDemo floatButtonDemo)
|
||||
{
|
||||
floatButtonDemo.CloseFloatButtonForm();
|
||||
}
|
||||
//// 清理上一个浮动按钮窗体
|
||||
//if (currControl is FloatButtonDemo floatButtonDemo)
|
||||
//{
|
||||
// floatButtonDemo.CloseFloatButtonForm();
|
||||
//}
|
||||
|
||||
// 检查是否已存在同名 TabPage
|
||||
foreach (var tab in tabs.Pages)
|
||||
@ -129,11 +198,12 @@ namespace DHSoftware.Views
|
||||
int width = tabs.Width;
|
||||
int height = tabs.Height;
|
||||
// 创建新 TabPage
|
||||
UserControl control =new UserDetetion(width, height);
|
||||
UserDetetion control = new UserDetetion(width, height);
|
||||
control._windows = Window;
|
||||
switch (name)
|
||||
{
|
||||
case "工位1":
|
||||
// control =
|
||||
// control =
|
||||
break;
|
||||
}
|
||||
|
||||
@ -144,7 +214,7 @@ namespace DHSoftware.Views
|
||||
|
||||
var tabPage = new AntdUI.TabPage
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
Dock = DockStyle.Fill,
|
||||
Text = name,
|
||||
};
|
||||
tabPage.Controls.Add(control);
|
||||
@ -162,5 +232,26 @@ namespace DHSoftware.Views
|
||||
{
|
||||
SelectMenu();
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (var dlg = new AddCubicleWindow())
|
||||
{
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
var newItem = new MenuItem(dlg.CubicleName);
|
||||
//newItem.IconSvg = "AppstoreOutlined";
|
||||
// 防止重复添加
|
||||
if (!menu.Items.Cast<MenuItem>().Any(m => m.Text == newItem.Text))
|
||||
{
|
||||
menu.Items.Add(newItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// AntdUI.Notification.warn(this, "新增工位失败", $"{dlg.CubicleName}已存在!", autoClose: 3, align: TAlignFrom.TR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user