How can “default” values in overridden WinForm controls be prevented?

前端 未结 3 1799
挽巷
挽巷 2021-01-14 11:45

I\'m trying to learn and grasp what and how C# does things. I\'m historically a Visual Foxpro (VFP) developer, and somewhat spoiled at the years of visual inheritance by cr

3条回答
  •  我在风中等你
    2021-01-14 11:49

    Here is a simple solution using the ReadOnlyAttribute in the derived class.

    class MyLabel : Label
    {
        [ReadOnly(true)]
        public override Font Font
        {
            get { return new Font(FontFamily.GenericMonospace, 10); }
            set { /* do nothing */ }
        }
    }
    

    The ReadOnlyAttribute will disable property editing in the VS.NET designer.

提交回复
热议问题