gpt4 book ai didi

c# - 如何在 C# 中将 numericupdown 控件添加到自定义属性网格?

转载 作者:行者123 更新时间:2023-11-30 21:01:20 24 4
gpt4 key购买 nike

如何将数字向上/向下控件添加到我的应用程序中的属性网格?

最佳答案

您需要创建一个 UI 类型编辑器,然后在其中创建向上/向下控件。我不确定是否有一种方法可以在设置中指定最小/最大。我对它们进行了硬编码。

public class UpDownValueEditor : UITypeEditor {
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) {
return UITypeEditorEditStyle.DropDown;
}

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
IWindowsFormsEditorService editorService = null;
if (provider != null) {
editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
}

if (editorService != null) {
NumericUpDown udControl = new NumericUpDown();
udControl.DecimalPlaces = 0;
udControl.Minimum = 0;
udControl.Maximum = 127;
udControl.Value = (UInt16)value;
editorService.DropDownControl(udControl);
value = (UInt16)udControl.Value;
}

return value;
}
}

按如下方式将其添加到您的设置中:

//MinimumVolume
[Description("When using a sound card for MIDI output use this to adjust the minimum volume.\r\n" +
"Set this to zero for output to play back expression as it was recorded."),
DisplayName("Minimum Volume"),
Editor(typeof(UpDownValueEditor), typeof(UITypeEditor)),
Category("MIDI")]
public UInt16 MinimumVolume { get { return Settings.MinimumVolume; } set { Settings.MinimumVolume = value; } }

关于c# - 如何在 C# 中将 numericupdown 控件添加到自定义属性网格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14291291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com