c# 枚举多选

using System;
public class Test
{
  TrainStyle trainStyle = TrainStyle.Null;
  void Add(TrainStyle ts)
  {
    
trainStyle |= ts;
  }

  void Remove(TrainStyle ts)
  {
    trainStyle &= (~ts);
  }

  bool Contain(TrainStyle ts)
  {
    return (trainStyle & ts)!= 0;
  }
}
[Flags]
public enum TrainStyle
{
    Null = 0,
    G = 1,
    D = 2 << 1,
    T = 2 << 2,
    K = 2 << 3,
    Z = 2 << 4,
    C = 2 << 5,
    Other = 2 << 6
}

 

转载于:https://www.cnblogs.com/jephone/p/7904666.html

C#的PropertyGrid控件中,下拉多选通常是指使用属性Grid来展示一个包含多个选项(如枚举、列表或其他可选择项)的属性,并允许用户从中选择多个值。PropertyGrid默认支持单选,但你可以通过自定义`PropertyDescriptor`或编写事件处理器来实现多选功能。 一种常见的做法是创建一个`CustomTypeDescriptor`,然后覆盖`GetProperties()`方法,以便在下拉列表中显示一个可以多选的组合框。例如,你可以使用`BoundedumericUpDown`或`CheckedListBox`作为`Browsable`属性的值。 下面是一个简单的示例: ```csharp public class CustomPropertyDescriptor : PropertyDescriptor { private List<string> choices; // ... public override Type ComponentType => /* ... */; public CustomPropertyDescriptor(string name, Type componentType, object defaultValue, Attribute[] attributes) : base(name, componentType, defaultValue, attributes) { choices = GetChoices(); // 获取你的选项列表 } // ... 其他必要方法 public override UITypeEditor GetTypeEditor() { return new MultiSelectUITypeEditor(choices); } } // 自定义UITypeEditor class MultiSelectUITypeEditor : UITypeEditor { private readonly List<string> choices; public MultiSelectUITypeEditor(List<string> choices) { this.choices = choices; } // ... 实现ITypeEditor的相关方法,包括编辑值和提供UI组件 } ``` 当你在PropertyGrid中设置这个自定义的`PropertyDescriptor`时,它会显示一个可以多选的下拉列表。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值