0

无法将顶级控件添加到控件请告诉我,如何在 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);
4

1 回答 1

0

我找到了解决方案。代替

FileEditor.DropDownControl(MenuList);

Point MenuCoords = (System.Windows.Forms.Control.MousePosition);
MenuList.Show(MenuCoords);
于 2013-10-03T06:55:11.677 回答