Results 1 to 2 of 2

Thread: [2005] Inherited Forms

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    179

    Question [2005] Inherited Forms

    We are using inherted forms and I am trying to control the form's title to keep it consistant within the application.

    An example of what I am doing is like this:

    base.vb <-- our base form that is inherited by the other forms
    form1.vb <-- form that is inheriteding base.vb

    If in form1.vb someone changes the me.text to anything then they clear it, now form1.vb shows me.text = "" or whatever they have in there overriding my inherited forms title.

    Long story short, can I lock the me.text so that base.vb overrides or cannot be changed by forms inheriting it?

    Thanks !
    Eroc

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Inherited Forms

    You'd have to shadow the Text property so that it did not set the corresponding base property.
    VB Code:
    1. Public Class BaseForm
    2.     Inherits Form
    3.  
    4.     'Hide the base Text behind a read-only property so it cannot be set.
    5.     'Also, don't show it in the Properties window.
    6.     <Browsable(False)> _
    7.     Public Shadows ReadOnly Property Text() As String
    8.         Get
    9.             Return MyBase.Text
    10.         End Get
    11.     End Property
    12.  
    13.     Public Sub New()
    14.         '...
    15.  
    16.         MyBase.Text = "This Title Cannot Be Changed"
    17.     End Sub
    18.  
    19. End Class
    Note though that because the base property is not declared Overridable you must declare the new property Shadows, which means that if the caller casts it as type Form they will be able to change the Text property and there is no way around that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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