Results 1 to 10 of 10

Thread: [RESOLVED] Inherit Centralize

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2013
    Posts
    69

    Resolved [RESOLVED] Inherit Centralize

    Hi all,
    I have forms and i added a Modules to Initialize all my Forms (change color, font and more).
    Now i want to add code Inherits all my form to System.Windows.Forms in my Modules

    Example:
    Form 1
    Code:
    Public Class Form1
        InitializeForms(Me)
    End Class
    Code:
    Public Class Form2
        InitializeForms(Me)
    End Class
    Code:
    Public Sub InitializeForms(ByRef Sender as Object)
        'Code to add Inherits Command [Inherits System.Windows.Form]
    End Sub
    How can i do this ?

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Inherit Centralize

    Well you would put all your module code into a separate project. (giving your project a clear namespace name)

    You can then import that project by adding it as a reference to your main project and by adding a Imports statement to the top of your form code make it available to each form e.g. 'Imports NamespaceName'
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2013
    Posts
    69

    Re: Inherit Centralize

    Quote Originally Posted by NeedSomeAnswers View Post
    Well you would put all your module code into a separate project. (giving your project a clear namespace name)
    How to do this? I don't understand. I'm Sorry because i'm still newbie.

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

    Re: Inherit Centralize

    To be honest, I'm completely confused as to what you want. your forms already do inherit from Windows.Forms... so I'm lost as to what it is exactly you want.
    Personally I wouldn't use Modules, but that's more a personal choice. If you're passing all your forms into the same function like that and making them with all the same settings, why not simply add a form with those settings already. Then when you add a form to your project, inherit from that form. Then you don't need a separate method or anything. And if you make a change to the "template", it will ripple out to all of the inherited forms.

    -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
    Lively Member
    Join Date
    Dec 2013
    Posts
    69

    Re: Inherit Centralize

    Quote Originally Posted by techgnome View Post
    To be honest, I'm completely confused as to what you want. your forms already do inherit from Windows.Forms... so I'm lost as to what it is exactly you want.
    Personally I wouldn't use Modules, but that's more a personal choice. If you're passing all your forms into the same function like that and making them with all the same settings, why not simply add a form with those settings already. Then when you add a form to your project, inherit from that form. Then you don't need a separate method or anything. And if you make a change to the "template", it will ripple out to all of the inherited forms.

    -tg
    Inherits system.windows.forms is just example. Actually i want inherit to 3rd party component (if u know devExpress). I want inherit to xtraForm.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Inherit Centralize

    Quote Originally Posted by jimzarthur View Post
    Inherits system.windows.forms is just example. Actually i want inherit to 3rd party component (if u know devExpress). I want inherit to xtraForm.
    So do it then. You don't do that in a method. You can't make a class inherit something at run time. It has to be part of the class declaration.

    Open the Solution Explorer and click the Show All Files button at the top. Expand the node for any of your forms and then double-click the item ending with "designer.vb". That is the auto-generated designer code file. You'll see the Inherits keyword at the top of the class. If you want to inherit other than System.Windows.Forms.Form then change it there.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Inherit Centralize

    Then simply make your own form inherit from xtra form rather than System.Windows.Form.

    1. Make sure you've got a reference to a dll that defines the DevExpress.ExtraEditors namespace and the XxtraForm form (I'm assuming they'll noth be in the same dll)
    2. Open up the designer code of your form
    3. It will probably say "Inherits System.Windows.Form" at the top of it. Change that to "Inherits DevExpress.XtraEditors.XtraForm" and you should be good to go.



    edit> Crossed over with JM.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2013
    Posts
    69

    Re: Inherit Centralize

    Quote Originally Posted by jmcilhinney View Post
    So do it then. You don't do that in a method. You can't make a class inherit something at run time. It has to be part of the class declaration.

    Open the Solution Explorer and click the Show All Files button at the top. Expand the node for any of your forms and then double-click the item ending with "designer.vb". That is the auto-generated designer code file. You'll see the Inherits keyword at the top of the class. If you want to inherit other than System.Windows.Forms.Form then change it there.
    Thanks anyway for your guidance. But all my forms has been created with System.Windows.Forms.Form and i want to Inherit to XtraForm Automatically in 1 place. In all my Forms have a InitializeObject(param) to centralize Initialize Form. That's i want to placed in InitializeObject Method. If u say i can't change class inherit something at Design Time, so i must change this manually like ur guidance. Thanks in advance JM.

  9. #9
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Inherit Centralize

    I'm pretty sure you can't do that (at least, not without some major hack). Inheritance isn't something an object does, it's something an object is. So when you say "Inherits System.Windows.Form" you are saying to the compiler, this thing I'm building is a type of Windows form and that's what the compiler builds for you. You can't change it later at run time.


    Edit> As an after thought, you could look at composing the functionality of the XtraForm rather than inheriting it. That's where you keep a reference to the parent class in the child object and you write code in the child object to "pass through" calls to the parent from the child. It means some more coding in your child objects but it does have the advantage that you can change the parent at run time. I think inheritance is still probably a better choice for you but if you're hell bent on handling this stuff at run time them composition is the beter alternative.
    Last edited by FunkyDexter; Oct 20th, 2014 at 08:26 AM.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Dec 2013
    Posts
    69

    Re: Inherit Centralize

    Quote Originally Posted by FunkyDexter View Post
    I'm pretty sure you can't do that (at least, not without some major hack). Inheritance isn't something an object does, it's something an object is. So when you say "Inherits System.Windows.Form" you are saying to the compiler, this thing I'm building is a type of Windows form and that's what the compiler builds for you. You can't change it later at run time.


    Edit> As an after thought, you could look at composing the functionality of the XtraForm rather than inheriting it. That's where you keep a reference to the parent class in the child object and you write code in the child object to "pass through" calls to the parent from the child. It means some more coding in your child objects but it does have the advantage that you can change the parent at run time. I think inheritance is still probably a better choice for you but if you're hell bent on handling this stuff at run time them composition is the beter alternative.
    Ok i will try ur step. Thanks for all ur help. I will mark this thread RESOLVED

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