Howto: Determine the Form that is inherited from another form.

Posted on 2004-11-17
Last Modified: 2010-04-24
I have this base Form:
Public Class FormReBind
    Inherits System.Windows.Forms.Form

    Event ReBinding()
#Region " Windows Form Designer generated code "
    Public Sub ReBind()
        RaiseEvent ReBinding()
    End Sub
End Class

and inherited Form is:
Public Class Form1
    Inherits FormReBind
In Form Main:
   Dim frm as Form
   If frm is FormReBind then <== Howto?
      'Place some code
   End if

Thanks for helping .
Question by:quangnv2005
    LVL 28

    Expert Comment

    Basically every form is inherited. Your form ReBind is inherited from Windows.Form
    LVL 4

    Accepted Solution


    I think what you need could be written like this :

    If frm.GetType.IsSubclassOf(GetType(FormReBind)) Then

    LVL 4

    Expert Comment

    Glom is right, but you have to put an instance of base class to get its type:

    Dim frm as New Form()
    Dim frmReBind as New FormReBind()

    If frm.GetType.IsSubclassOf( frmReBind.GetType() ) Then
          'Place some code
    End if

    LVL 4

    Expert Comment

    Hi Jigit,
    I have tested my code, and the name of the class is enough for the GetType function. No need to have an instance ;)

    Author Comment

    Thanks Glom, it's work. And with your approach I found another way, like:

    If TypeOf frm is FormReBind Then
        'Place some code
    End If

    Thank for your help again.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now