下面的代码是一个自定义控件。在 Visual Studio 设计器中使用此控件会导致 Visual Studio 在没有任何明显细节的情况下崩溃。
我正在使用 Visual Studio 2008。
我是不是做错了什么?
using System;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace InstalacionesSayma.GUI
{
public class CustomControlTest : Panel
{
private Label _label;
public CustomControlTest()
{
_label = new Label();
this.Controls.Add(_label);
}
public override Font Font
{
get
{
return _label.Font;
}
set
{
_label.Font = value;
}
}
}
}
最佳答案
崩溃的发生是因为您的 Font 行为。您正在覆盖面板的 Font 属性的预期行为。将您的字体代码更改为以下代码会使崩溃消失:
public override Font Font
{
get
{
return base.Font;
}
set
{
base.Font = value;
_label.Font = value;
}
}
关于c# - 自定义控件导致 Visual Studio 2008 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3840108/