I'm inheriting a control from TextBox and I want to disable the MaxLength property and fix it at 5. MaxLength is a virtual property of Control so I should override it.
Now the MaxLength property should be read-only since I only have a 'get' modifier, right? If I assign to the MaxLength property of an instance of FixedTextBox there are no compile errors.Code:public FixedTextBox() { base.MaxLength = 5; } [Browsable(false)] [DefaultValue(5)] public override int MaxLength { get { return 5; } }
Why does this not generate a compile error? Is it because the override modifier only overrides the 'get' modifier of Control.MaxLength but leaves the 'set' modifier alone?Code:fixedTextBox1.MaxLength = 0;
Using the 'new' modifier fixes this issue and I understand why, I just don't understand why 'override' does not work.




Reply With Quote