Results 1 to 6 of 6

Thread: Inherit Form

  1. #1

    Thread Starter
    New Member At--o's Avatar
    Join Date
    Aug 2011
    Posts
    9

    Inherit Form

    Code:
        Public Class aaMyForm
        Inherits Windows.Forms.Form
    Added some controls. Build it, add the .DLL as reference to my other project.
    In my other project:

    Code:
        Imports MyLib
        Public Class XForm
        Inherits aaMyForm



    The events from aaMyForm execute correctly but the controls added to it are not shown on XForm. I have found some info about set Modifiers Protected in order to be able to change the functionality of the controls but havent found anything about why the controls aren display on the XForm.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Inherit Form

    in your Solution Explorer, click the Show all files button, then open XForm.Designer.vb + change the inherits line from:

    vb Code:
    1. Inherits System.Windows.Forms.Form

    to:

    vb Code:
    1. Inherits aaMyForm

    then delete that same line from Public Class XForm

  3. #3

    Thread Starter
    New Member At--o's Avatar
    Join Date
    Aug 2011
    Posts
    9

    Re: Inherit Form

    Hi Paul, it turns out that the XForm.Designer.vb was already inheriting from aaMyForm, so I just deleted the same line from Public Class XForm but still no control is shown.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Inherit Form

    delete any compiled code...(dlls, exes, etc)... zip up the projects (using winzip, don't make a rar file) and attach it... clearly something isn't right and what ever it is isn't coming through the posts ...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member At--o's Avatar
    Join Date
    Aug 2011
    Posts
    9

    Re: Inherit Form

    I think I found the problem. I was creating a new class that inherited from Form instead of creating a new form which I thought was pretty much the same (both are classes that inherit from form) but the new form, has the .designer.vb file where the InitializeComponent resides, while when creating a new class that inherits form Form doesn't and so the InitializeComponent is not on the Partial part of the class.

    So the solution is creating MyForm class directly by adding a new form instead of creating a class that inherits from Form. Now if a form in a different project inherits from MyForm it does contain the controls. I would still like to know the exact reason for that. Thank you all.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Inherit Form

    That's pretty much what .Paul. was saying in his first post. All forms inherit from Form. Any new form you create will also inherit from Form. This is a child class of Form. Any new form that you want to have the same functionality as that child class has to inherit from that child class and not from Form directly. However, any such new sub has to call the InitializeComponent method found in the child class. Unfortunately, InitializeComponent is declared Private in the child class, so the derived class can't call it directly. If you take a look at InitializeComponent, you see that that is where all the controls are being created, so if that method isn't called....you get none of those controls, because they were never created.

    There are two possible solutions:

    1) Make the child InitializeComponents Protected. This has some ramifications, so it might not be a good idea. The problem would be that the designer for the derived form will not work right.

    2) In the constructor of the derived form, explicitly call MyBase.New
    My usual boring signature: Nothing

Tags for this Thread

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