Commit 98769f7e 刘韬

Combox添加 选项disable功能, 以*开头的value开头

1 个父辈 eea8cf07
......@@ -201,6 +201,7 @@ namespace HZH_Controls.Controls
set
{
_source = value;
_selectedIndex = -1;
_selectedValue = "";
_selectedItem = new KeyValuePair<string, string>();
......@@ -557,11 +558,26 @@ namespace HZH_Controls.Controls
{
if (_frmAnchor != null && !_frmAnchor.IsDisposed && _frmAnchor.Visible)
{
SelectedValue = sender.ToString();
string selectedValue = sender.ToString();
// Check if the selected item starts with *
var selectedItem = _source.FirstOrDefault(x => x.Key == selectedValue);
if (selectedItem.Value != null && selectedItem.Value.StartsWith("*"))
{
// Don't change selection or trigger event for disabled items
_frmAnchor.Close();
return;
}
SelectedValue = selectedValue;
_frmAnchor.Close();
}
}
// Add a method to check if an item is disabled
private bool IsItemDisabled(KeyValuePair<string, string> item)
{
return item.Value.StartsWith("*");
}
/// <summary>
/// Handles the Load event of the UCComboBox control.
/// </summary>
......
......@@ -205,8 +205,29 @@ namespace HZH_Controls.Controls
{
if (lstSource != null && index < lstSource.Count)
{
btn.BtnText = lstSource[index].Value;
// 检查是否是禁用项(以*开头)
bool isDisabled = lstSource[index].Value.StartsWith("*");
string displayText = isDisabled ?
lstSource[index].Value.Substring(1) :
lstSource[index].Value;
btn.BtnText = displayText;
btn.Tag = lstSource[index].Key;
// 设置禁用项的样式
if (isDisabled)
{
btn.FillColor = Color.FromArgb(240, 240, 240); // 灰色背景
btn.BtnForeColor = Color.Gray; // 灰色文字
btn.Enabled = false; // 禁用按钮
}
else
{
btn.FillColor = Color.White;
btn.BtnForeColor = Color.FromArgb(66, 66, 66);
btn.Enabled = true;
}
index++;
}
else
......@@ -309,7 +330,7 @@ namespace HZH_Controls.Controls
void btn_BtnClick(object sender, EventArgs e)
{
var btn = (UCBtnExt)sender;
if (btn.Tag == null)
if (btn.Tag == null || !btn.Enabled) // 检查按钮是否被禁用
return;
SelectBtn = btn;
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!