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
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.
Instead of using the "ReadOnlyAttribute", try using the "DefaultValueAttribute" instead. If I remember correctly, the designer shouldn't create code to set the property if the current value matches the value stored in the "DefaultValueAttribute".
Try adding the ReadOnly attribute to the properties of your derived classes:
[ReadOnly(true)]
public override Font Font
{
get{ // Your Implementation Here }
set{ // Don't really care,do you? }
}
The ReadOnlyAttribute should enforce the ReadOnly behavior at design time.