Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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

0
anwarmir
Asked:
anwarmir
  • 5
  • 2
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now