0
我有一个具有几个参数和几个属性的自定义活动。将活动放入重新托管的设计器时,可以从用户可以输入值或变量名称等属性窗口中看到参数和属性。更改自定义活动属性窗口中的控件
对于其中一个属性(在属性窗口中),我不会不希望用户能够输入它,而是用组合框代替文本框,以便他们可以从值列表中进行选择。这,我似乎无法找到答案。
我已经使用已标记为已解决的现有条目中的一些代码,但我的请求是稍有不同的要求。
在我的自定义活动,我已经把有关财产之上的以下内容:
[EditorAttribute(typeof(ComboBoxTest), typeof(System.Drawing.Design.UITypeEditor))]
,并创造了ComboBoxTest类,自UITypeEditor继承:
public class ComboBoxTest : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
ListBox list = new ListBox();
//ComboBox list = new ComboBox();
// Your code here to populate the list box with your items
list.Items.Add("A");
list.Items.Add("B");
list.Items.Add("C");
EventHandler onclick = (sender, e) =>
{
editorService.CloseDropDown();
};
list.Click += onclick;
editorService.DropDownControl(list);
list.Click -= onclick;
return (list.SelectedItem != null) ? list.SelectedItem : null;
}
}
但是,下降的时候活动传递给设计者,属性在属性窗口中仍然有文本框,并且不出现组合框。我甚至无法调试它,因为它没有触及任何断点。
有人会碰巧知道A)我是正确的做法还是B)如果我在某个地方发生了错误,甚至C)有一个更好的方法,我应该使用。
我希望所有有意义。感谢您的阅读!
亲切的问候, 迈克尔