c# - 自定义控件导致 Visual Studio 2008 崩溃

标签 c# .net winforms crash custom-controls

下面的代码是一个自定义控件。在 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/

相关文章:

c# - 如何将值从 View 传递到 Controller

c# - 将字符串转换为指定的日期格式

c# - 为什么手动更改值时不会在 NumericUpDown 控件上触发 ValueChanged 事件?

c# - 如何将数据网格添加到 winforms 的组合框中?

c# - 如何在 Windows 窗体上显示动画 GIF (c#)

c# - EF 和 IHostedService 的多个实例

c# - 使用 ADAL v3 使用 ClientID 对 Dynamics 365 进行身份验证

.net - 文件版本与程序集版本

c# - 在 Entity Framework 4.3 中设置命令超时

c# - 动态填充的 TableLayoutPanel 性能下降