0 1PropertyGrid显示

        [Browsable(true)]
        [DisplayName("属性指標値の有無")]
        public bool HAS_INDICATOR_BOOL
        {
            set
            {
                _has_indicator_bool = value;
                if (_has_indicator_bool)
                {
                    _has_indicator = 1;
                }
                else
                {
                    _has_indicator = 0;
                }
            }
            get
            {
                if (_has_indicator == 1)
                {
                    _has_indicator_bool = true;
                }
                else
                {
                    _has_indicator_bool = false;
                }
                return _has_indicator_bool; }
        }
        /// <summary>
        ///
        /// </summary>
        ///
        [Browsable(false)]
        [DisplayName("属性指標値の有無")]
        //[TypeConverter(typeof(IntBoolConverter))]
        public int HAS_INDICATOR
        {
            set { _has_indicator = value; }
            get { return _has_indicator; }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
是的,WinForm的PropertyGrid可以通过使用自定义属性描述符和UI类型编辑器来显示RadioButton。 要实现这个功能,你需要首先创建一个自定义属性描述符类,该类继承自System.ComponentModel.PropertyDescriptor。在这个类中,你需要重写GetValue和SetValue方法,以便从类的属性中获取和设置值。接下来,你需要创建一个自定义的UI类型编辑器类,该类继承自System.Drawing.Design.UITypeEditor,并重写EditValue方法,以便在PropertyGrid显示RadioButton。 下面是一个示例: ``` public class RadioButtonPropertyDescriptor : PropertyDescriptor { private readonly RadioButtonGroup _group; private readonly RadioButton _button; public RadioButtonPropertyDescriptor(string name, Attribute[] attrs, RadioButtonGroup group) : base(name, attrs) { _group = group; _button = new RadioButton() { Text = name, Checked = false }; _button.CheckedChanged += (sender, args) => { if (_button.Checked) { _group.Value = _button.Text; } }; } public override Type ComponentType => typeof(RadioButtonGroup); public override bool IsReadOnly => false; public override Type PropertyType => typeof(string); public override bool CanResetValue(object component) => false; public override object GetValue(object component) => _button.Checked ? _button.Text : null; public override void ResetValue(object component) { } public override void SetValue(object component, object value) => _button.Checked = (string)value == _button.Text; public override bool ShouldSerializeValue(object component) => false; public override void AddValueChanged(object component, EventHandler handler) => _button.CheckedChanged += handler; public override void RemoveValueChanged(object component, EventHandler handler) => _button.CheckedChanged -= handler; public override object GetEditor(Type editorBaseType) => new RadioButtonEditor(); public override bool IsBrowsable => true; } public class RadioButtonGroup { private string _value; private PropertyDescriptorCollection _properties; public RadioButtonGroup(PropertyDescriptorCollection properties) { _properties = properties; } public string Value { get => _value; set { if (_value != value) { _value = value; _properties.Find(_value, true)[0].SetValue(this, true); } } } } public class RadioButtonEditor : UITypeEditor { private IWindowsFormsEditorService _editorService; public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { _editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (_editorService == null) return value; var group = (context.Instance as RadioButtonGroup); var buttons = group != null ? group.Value : null; var property = context.PropertyDescriptor as RadioButtonPropertyDescriptor; var radioButton = property != null ? property.RadioButton : null; var panel = new FlowLayoutPanel() { AutoSize = true }; foreach (PropertyDescriptor prop in context.PropertyDescriptorCollection) { var radioButtonProp = prop as RadioButtonPropertyDescriptor; if (radioButtonProp != null) { panel.Controls.Add(radioButtonProp.RadioButton); if (radioButtonProp.RadioButton.Checked) { buttons = radioButtonProp.RadioButton.Text; } } } if (_editorService.ShowDialog(panel) == DialogResult.OK) { return buttons; } return value; } public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) => UITypeEditorEditStyle.DropDown; } ``` 在这个示例中,我们创建了一个名为RadioButtonPropertyDescriptor的自定义属性描述符类,它包含了一个RadioButton作为属性的UI类型编辑器。我们还创建了一个名为RadioButtonGroup的类,它包含了一个字符串值和一个属性描述符集合。最后,我们还创建了一个名为RadioButtonEditor的UI类型编辑器,用于在PropertyGrid显示RadioButton。 使用这些类,你可以像这样在PropertyGrid显示RadioButton: ``` var properties = new PropertyDescriptorCollection(new PropertyDescriptor[] { new RadioButtonPropertyDescriptor("Option1", new Attribute[] { }, group), new RadioButtonPropertyDescriptor("Option2", new Attribute[] { }, group), new RadioButtonPropertyDescriptor("Option3", new Attribute[] { }, group), }); var group = new RadioButtonGroup(properties); var propertyGrid = new PropertyGrid() { SelectedObject = group }; ``` 在这个示例中,我们创建了一个包含三个RadioButton的RadioButtonGroup,并将其传递给了一个PropertyGrid。当用户选择一个RadioButton时,它的值将自动保存到RadioButtonGroup的Value属性中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值