C# 试图将用户控件添加到Visual Studio窗体时崩溃

C# 试图将用户控件添加到Visual Studio窗体时崩溃,c#,visual-studio-2013,C#,Visual Studio 2013,我创建了一个名为开关的UserControl。 我构建了我的项目,这个UC成功地显示在我的工具箱中。 因此,我试图通过将其拖动到表单中,将其添加到我的frmMain。但此时,Visual Studio始终显示一条错误消息: 无法为堆栈创建新的保护页 单击确定后,devenv.exe崩溃 我必须提到,我有另一个用户控件,它与开关位于同一名称空间和文件夹中。这个UC很好用 这是我的开关用户控件的代码: 公共部分类开关:UserControl { 私有矩形; private int xOn=0;//

我创建了一个名为
开关的
UserControl
。 我构建了我的项目,这个UC成功地显示在我的工具箱中。 因此,我试图通过将其拖动到表单中,将其添加到我的
frmMain
。但此时,Visual Studio始终显示一条错误消息:

无法为堆栈创建新的保护页

单击确定后,
devenv.exe
崩溃

我必须提到,我有另一个用户控件,它与
开关
位于同一名称空间和文件夹中。这个UC很好用

这是我的
开关
用户控件的代码:

公共部分类开关:UserControl
{
私有矩形;
private int xOn=0;//开关打开时,开关矩形x位置
private int xOff=0;//当开关关闭时,切换矩形x位置
专用颜色开关颜色=颜色。黑色;
私有颜色OuterRectangleColor=Color.DarkGray;
私有颜色InnerRectangleColor
{
获取{返回this.On?Color.DodgerBlue:InnerRectangleColor;}
}
{get;set;}上的公共布尔
公共交换机()
{
初始化组件();
重新加载SwitchRectangle();
xOn=this.Width-switchRectangle.Width;
}
私有无效开关_Paint(对象发送器,PaintEventArgs e)
{
e、 图形。清晰(此。背景色);
//创建内部矩形,每边比ClientRectangle小2倍
const int amountToDecrease=2;
Rectangle innerRectangle=新矩形(this.ClientRectangle.X+amountToDecrease,this.ClientRectangle.Y+amountToDecrease,
this.ClientRectangle.Width-数量减少*2,this.ClientRectangle.Height-数量减少*2);
重新加载SwitchRectangle();
e、 Graphics.DrawRectangle(新笔(OuterRectangleColor),this.ClientRectangle);//绘制外矩形
e、 Graphics.FillRectangle(新的SolidBrush(InnerRectangleColor),innerRectangle);//填充内部矩形
e、 FillRectangle(新的SolidBrush(SwitchColor)、switchRectangle);
}
私有void重载SwitchRectangle()
{
int x=这个。On?xOn:xOff;
switchRectangle=新矩形(x,0,this.Width/5,this.Height);
}
}
这就是问题所在:

private Color InnerRectangleColor
{
    get { return this.On ? Color.DodgerBlue : InnerRectangleColor; }
}

这个设置为false时,这里有无限递归。

多亏了Sriram Sakthivel,我这样解决了我的问题:


哦,谢谢!现在我明白了。我想写OuterRectangleColor,而不是InnerRectangleColor:D
private Color InnerRectangleColor
{
    get { return this.On ? Color.DodgerBlue : OuterRectangleColor; }
}