无法将顶级控件添加到控件请告诉我,如何在 PropertyGrid 中显示 ContextMenuStrip?为此,我使用以下代码:
public class SaveFileNameEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService FileEditor =
provider.GetService(typeof(IWindowsFormsEditorService)) as
IWindowsFormsEditorService;
ContextMenuStrip MenuList = null;
ToolStripMenuItem MenuItem = null;
if (FileEditor != null)
{
MenuList = new ContextMenuStrip ();
MenuItem = new ToolStripMenuItem("Add File...");
MenuList.Items.Add(MenuItem);
MenuItem = new ToolStripMenuItem("Save File ...");
MenuList.Items.Add(MenuItem);
MenuItem = new ToolStripMenuItem("Delete File ...");
MenuList.Items.Add(MenuItem);
FileEditor.DropDownControl(MenuList);
MenuList.Show();
}
return value;
}
}
但是我在线收到错误消息“无法将顶级控件添加到控件”
FileEditor.DropDownControl(MenuList);