passing a form to a constructor.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Just Me

    #1

    passing a form to a constructor.

    I want to be able to access the control members of a form from within a
    class. So i designed my constructor something like this

    Form1 parentForm;

    ClassName ( Form1 frm )
    {

    parentForm = frm;


    }


    But when I try and pass the form to the class it errors.


    ClassName myClass( this );


    What am I doing wrong ???


    Cheers




  • Alberto Poblacion

    #2
    Re: passing a form to a constructor.

    "Just Me" <news.microsoft .comwrote in message
    news:ewALgw8RIH A.4196@TK2MSFTN GP04.phx.gbl...
    >I want to be able to access the control members of a form from within a
    >class. So i designed my constructor something like this
    >
    Form1 parentForm;
    >
    ClassName ( Form1 frm )
    {
    parentForm = frm;
    }
    >
    But when I try and pass the form to the class it errors.
    >
    ClassName myClass( this );
    >
    What am I doing wrong ???
    I think that what you want to do is this:

    ClassName myClass = new ClassName(this) ;

    It will only work if it is done inside Form1, since otherwise "this"
    would not be of the adequate type to pass to the constructor that you
    defined.

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: passing a form to a constructor.

      <"Just Me" <news.microsoft .com>wrote:

      <snip>
      But when I try and pass the form to the class it errors.
      >
      >
      ClassName myClass( this );
      >
      >
      What am I doing wrong ???
      Well, that's not the syntax used for a constructor call. You need:

      ClassName myClass = new ClassName(this) ;

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      World class .NET training in the UK: http://iterativetraining.co.uk

      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: passing a form to a constructor.

        Hi,


        You need to get a book of C# , some basic stuff like syntax, etc.

        --
        Ignacio Machin
        The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

        Mobile & warehouse Solutions.
        "Just Me" <news.microsoft .comwrote in message
        news:ewALgw8RIH A.4196@TK2MSFTN GP04.phx.gbl...
        >I want to be able to access the control members of a form from within a
        >class. So i designed my constructor something like this
        >
        Form1 parentForm;
        >
        ClassName ( Form1 frm )
        {
        >
        parentForm = frm;
        >
        >
        }
        >
        >
        But when I try and pass the form to the class it errors.
        >
        >
        ClassName myClass( this );
        >
        >
        What am I doing wrong ???
        >
        >
        Cheers
        >
        >
        >
        >

        Comment

        Working...