Inherittance Question

Hello I have base from. On this form I have a protected property FormType. Now I have derived forms which inherit from this baseform. What I want to to do is set the base form property to a particular form type when a derived form is opnened and thus positioning and making certain controls invisible. I have tried to use the following code in the activated event of the derived form :

mybase.formtype = 1

however I cant seem to set the property of the base form in this event.

Can anybody help

anwarmirAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

S-TwilleyCommented:
Public Class SimpleForm
    Inherits System.Windows.Forms.Form   'taking a guess on this line :P

    private iFType As Integer

    Public Property FormType() As Integer
        Get
            Return iFType
        End Get
        Set(ByVal Value As Integer)
            iFType = Value
        End Set
    End Property

   '... rest of form code
End Class

=================

Public Class ExtendedForm
    Inherits SimpleForm

    Protected Overrides Sub OnActivated(ByVal e As System.EventArgs)
        MyBase.FormType = 1 'or whatever
    End Sub
End Class

===================

I've not tested this, but I think that's how it should all go... is that the same as you have?
0
anwarmirAuthor Commented:
No sorry this still does not work. In the load event of the the base form I have code to format the form depending upon which form has been opnened. Using the formtype property. However this gets executed before i can set the formtype of the base form in the derived forms.  

I followed your steps
Made the base class activivated event overridable
 Protected Overridable Sub PrintRange_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
  End Sub

In the derived class I used the foolwoing code in the activated event

Protected Overrides Sub Printrange_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        MyBase.FormType = PrintRange.PrintFormType.ReprintPaymentReceipts
    End Sub

I also had to change the sub name to PrintRange  as I was getting an error. However this still does not execute until after the load event of the base form.
 

0
S-TwilleyCommented:
How about having a method to format the form in the base form ... which takes as an argument the form type.

Then in the load event of the derived form... call

MyBase.FormatIt(FormTypeValue)

I think that's kind of what you are after... I'm trying to do too many things at once at the mo so im sorry if that was a lil vague
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

anwarmirAuthor Commented:
OK I will try that...But it would be good to know if It is possible to change the tha base form property from a derived form so that it can be manipulated in the load event of the base class. Apologies not neccessary really appreciate your help
0
S-TwilleyCommented:
well you can try this (I think its nearer to what you were asking) ....

Public Class SimpleForm
    Inherits System.Windows.Forms.Form

    Private iFType As Integer

#Region " Windows Form Designer generated code "

    Public Sub New(ByVal FormType As Object)
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

        ' DO FORMATTING HERE DEPENDING ON FORM TYPE

        If FormType.ToString = "TEST" Then
            MsgBox("Wahoo")
        End If
    End Sub

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub
   ' THE REST OF FORM GENERATED CODE
    ' ....
     ' i left it out to save space
End Class

Public Class ExtendedForm
    Inherits SimpleForm



    Public Sub New()
        MyBase.New("TEST")
    End Sub
End Class
0
S-TwilleyCommented:
Then on a different extended form you might have :

Public Class AnotherExtendedForm
    Inherits SimpleForm

    Public Sub New()
        MyBase.New("SECONDTYPE")

    End Sub
End Class
0
S-TwilleyCommented:
Ok, hope either that workaround i posted, or the solution above works... just so you know, I'm going to be out of service for a few hours (need some sleep), so I won't be able to answer anything for a bit :P
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.