136 lines
4.7 KiB
C#
136 lines
4.7 KiB
C#
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 AntdUI;
|
|
|
|
namespace DHSoftware.Views
|
|
{
|
|
public partial class SettingWindow : Window
|
|
{
|
|
public SettingWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
AntdUI.TooltipComponent tooltip = new AntdUI.TooltipComponent()
|
|
{
|
|
Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134))),
|
|
};
|
|
tooltip.ArrowAlign = AntdUI.TAlign.Right;
|
|
tooltip.SetTip(btnAdd, "新增工位");
|
|
|
|
|
|
|
|
}
|
|
|
|
private void Menu_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Right)
|
|
{
|
|
// 转换坐标到控件内部坐标系(考虑滚动条)
|
|
Point clickPoint = new Point(e.X, e.Y + menu1.ScrollBar.Value);
|
|
|
|
// 递归查找命中的菜单项
|
|
MenuItem clickedItem = FindClickedItem(menu1.Items, clickPoint);
|
|
|
|
if (clickedItem != null)
|
|
{
|
|
// 显示节点名称弹窗
|
|
//MessageBox.Show($"右键点击的节点: {clickedItem.Text}");
|
|
|
|
var menulist = new AntdUI.IContextMenuStripItem[]
|
|
{
|
|
new AntdUI.ContextMenuStripItem("关联相机", "")
|
|
{
|
|
IconSvg = "VideoCameraAddOutlined"
|
|
}
|
|
};
|
|
AntdUI.ContextMenuStrip.open(menu1, it =>
|
|
{
|
|
if (it.Text == "关联相机")
|
|
{
|
|
using (var dlg = new AddCameraWindow())
|
|
{
|
|
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;
|
|
}
|
|
|
|
// 递归检查子项(如果展开)
|
|
if (item.Expand && item.Sub != null)
|
|
{
|
|
var childResult = FindClickedItem(item.Sub, clickPoint);
|
|
if (childResult != null) return childResult;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
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 (!menu1.Items.Cast<MenuItem>().Any(m => m.Text == newItem.Text))
|
|
{
|
|
menu1.Items.Add(newItem);
|
|
}
|
|
else
|
|
{
|
|
AntdUI.Notification.warn(this, "新增工位失败", $"{dlg.CubicleName}已存在!", autoClose: 3, align: TAlignFrom.TR);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void menu1_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
//if (e.Button == MouseButtons.Right)
|
|
//{
|
|
// var menu =sender as Menu;
|
|
// if (menu?.Items.Count == 0)
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
//}
|
|
}
|
|
}
|
|
}
|
|
|