Results 1 to 5 of 5

Thread: [2005] Constructor question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    [2005] Constructor question

    How can I put additional method if I want to add a constructor. Like example with Form Class, when I add constructor, it always add a method called InitializeComponent() and a comment

    vb Code:
    1. Public Sub New()
    2.  
    3.     ' This call is required by the Windows Form Designer.
    4.     InitializeComponent()
    5.  
    6.     ' Add any initialization after the InitializeComponent() call.
    7.  
    8. End Sub

    Regards

    Michael
    Check my Blog at VB Corner,Component Crafts

  2. #2
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2005] Constructor question

    Feel free to insert any other method calls or code you want in there. InitializeComponent is always called regardless of whether you explicitly create the constructor or not. Basically it just initializes all the controls and components on the form and shows them. You can add other method calls after you call that one.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Surabaya, Indonesia
    Posts
    163

    Re: [2005] Constructor question

    What I mean is, when I insert a constructor in a form class, it always insert InitializeComponent() automatically. I want my class has this ability too, since my class is inherited by several class and all of them must initiate the same method if I insert a constructor...
    Check my Blog at VB Corner,Component Crafts

  4. #4
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2005] Constructor question

    I'm not really sure what you mean. You wrote your own class? Is it inheriting from the System.Windows.Forms.Form class? You can call the InitializeComponent method wherever you want, even if the constructor is overloaded.

    Maybe I'm just tired but I can't fully understand what you mean.

  5. #5
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: [2005] Constructor question

    You can create your own ItemTemplate in VS2005 that will construct a default class with any comments or methods already defined. Try search google for ItemTemplate example.

    http://msdn.microsoft.com/msdnmag/is...CodeTemplates/
    Last edited by Jumpercables; Dec 18th, 2007 at 11:25 PM.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

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