Everything You Wanted to Know About Forms Inheritance in VB.Net - What’s New in This Article
(Page 4 of 6 )
If you simply inherit the form, you will not be able to change the properties of the Controls which you have placed in the base form. This example covers:
- How to inherit the form
- How make custom properties
- How to use the custom properties from the Child form
- How you change the properties of the controls from the parent form, which are not in the parent form (i.e. they are in the Child forms)
- How to override the functionality of the Parent form from the Child Form
- How to change the properties of the inherited controls at design time (i.e. how to reposition the controls, set different properties, etc.)
1) How to inherit the form
Open the child form and replace the ChildForm’s Inherits line to <name of the parent form> from <System.Windows.Forms.Form>
Base Form:
Public Class PMainForm
Inherits System.Windows.Forms.Form
Child Forms:
Public Class ChildForm
Inherits PmainForm
2) How to make custom properties
Open the Parent Form and create a property (having a scope as Protected Friend)
'CurrentPosition Property
Dim LPosition As Long
Protected Property Position() As Long
Get
Return LPosition
End Get
Set(ByVal Value As Long)
LPosition = Value
End Set
End Property
3) How to use the custom properties from the Child form
Open the child Form. Use Me.<propertyName> to change the property. For example, we are changing the property in the Load event of the child form.
Private Sub CForm3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Position = 99
End Sub
Next: What's New in This Article, Cont'd >>
More VB.Net Articles
More By Saurabh Verma