Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何调试ToolStrip错误“';儿童';是否不是此父级的子控件;?_C#_.net_Custom Controls_Windows Forms Designer - Fatal编程技术网

C# 如何调试ToolStrip错误“';儿童';是否不是此父级的子控件;?

C# 如何调试ToolStrip错误“';儿童';是否不是此父级的子控件;?,c#,.net,custom-controls,windows-forms-designer,C#,.net,Custom Controls,Windows Forms Designer,我已经创建了一个自定义ToolStrip控件和ToolStripControl控件,以便我可以完全自定义它们的所有部分,主要是悬停事件,但是我在设计器中遇到了一个问题,它引发了以下错误: “child”不是此父级的子控件 这是我添加控件时的代码 private void ToolStripPro_ControlAdded(object sender, ControlEventArgs e) { if (!CheckType(e.Control.GetType(), typeof(Tool

我已经创建了一个自定义ToolStrip控件和ToolStripControl控件,以便我可以完全自定义它们的所有部分,主要是悬停事件,但是我在设计器中遇到了一个问题,它引发了以下错误:

“child”不是此父级的子控件

这是我添加控件时的代码

private void ToolStripPro_ControlAdded(object sender, ControlEventArgs e)
{
    if (!CheckType(e.Control.GetType(), typeof(ToolStripProControl)))
    {
        this.Controls.Remove(e.Control);
    }

    Invalidate();
}
以及上面引用的my
CheckType
函数

private bool CheckType(Type check, Type checkType)
{
    if (check == checkType)
    {
        return true;
    }
    else
    {
        if (check.BaseType != null)
        {
            return CheckType(check.BaseType, checkType);
        }
        else
        {
            return false;
        }
    }
}
下面是
ToolStripPro
控件的类声明

[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] 
public partial class ToolStripPro : UserControl

我认为其他一切都是VisualStudio和设计师所固有的。我可能错了,但这应该能让我了解我的情况。

最好添加您认为相关的代码,因为问题是,它没有任何事情要做,可能会在适当的时候被搁置。@halfer刚刚添加了一些最相关的代码