Files
2026-01-16 19:25:21 +08:00

85 lines
2.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Modbus.Device;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Microsoft.SolverFoundation.Solvers.CspDomain;
namespace LaserFlashTesterControl
{
public partial class EditableComboBoxControl : UIPanel
{
public UIComboBox ComboBox { get; private set; }
private UIButton btnAdd;
private UIButton btnDelete;
public event Action OnAddItem;
public event Action OnDeleteItem;
public EditableComboBoxControl()
{
this.Height = 32;
this.Padding = new Padding(2, 2, 2, 2);
ComboBox = new UIComboBox();
ComboBox.Dock = DockStyle.Fill;
ComboBox.Margin = new Padding(0, 0, 80, 0); // 从70调整为80增加10像素空间
ComboBox.ShowClearButton = true;
btnAdd = new UIButton();
btnAdd.Text = "+";
btnAdd.Size = new Size(30, 28);
btnAdd.Dock = DockStyle.Right;
// 增加按钮左外边距(向右移动)
btnAdd.Margin = new Padding(18, 2, 2, 2); // 从8调整为18多右移10像素
btnAdd.Click += (s, e) => OnAddItem?.Invoke();
btnDelete = new UIButton();
btnDelete.Text = "-";
btnDelete.Size = new Size(30, 28);
btnDelete.Dock = DockStyle.Right;
// 增加按钮左外边距(向右移动)
btnDelete.Margin = new Padding(18, 2, 0, 2); // 从8调整为18多右移10像素
btnDelete.Click += (s, e) => OnDeleteItem?.Invoke();
this.Controls.Add(ComboBox);
this.Controls.Add(btnAdd);
this.Controls.Add(btnDelete);
}
public void AddItem(object item)
{
if (!ComboBox.Items.Contains(item))
{
ComboBox.Items.Add(item);
ComboBox.SelectedItem = item;
}
}
public void DeleteSelectedItem()
{
if (ComboBox.SelectedIndex != -1)
{
ComboBox.Items.RemoveAt(ComboBox.SelectedIndex);
}
}
}
}