Results 1 to 6 of 6

Thread: override in inherited control to disable property

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    override in inherited control to disable property

    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.

    Code:
    public FixedTextBox() {
    	base.MaxLength = 5;
    }
    
    [Browsable(false)]
    [DefaultValue(5)]
    public override int MaxLength {
    	get {
    		return 5;
    	}
    }
    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:
    fixedTextBox1.MaxLength = 0;
    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?

    Using the 'new' modifier fixes this issue and I understand why, I just don't understand why 'override' does not work.
    Last edited by wey97; Dec 29th, 2009 at 11:33 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width