Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. CreateInstance problem

CreateInstance problem

Scheduled Pinned Locked Moved C#
helptutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tavbi
    wrote on last edited by
    #1

    Hi, can I with CreateInstance create instance of form that requires parameters? Example: frmShopGood frmTemp = new frmShopGood(new DSBasis()); I tried this, but what can I do with parameter "new DSBasis()" Form myForm = (Form)Activator.CreateInstance(Type.GetType(formName)); Thanks, Jure

    C 1 Reply Last reply
    0
    • T Tavbi

      Hi, can I with CreateInstance create instance of form that requires parameters? Example: frmShopGood frmTemp = new frmShopGood(new DSBasis()); I tried this, but what can I do with parameter "new DSBasis()" Form myForm = (Form)Activator.CreateInstance(Type.GetType(formName)); Thanks, Jure

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Tavbi wrote:

      can I with CreateInstance create instance of form that requires parameters?

      Have you read the documentation for CreateInstance[^]? Perhaps this[^] will help.


      Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

      T 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Tavbi wrote:

        can I with CreateInstance create instance of form that requires parameters?

        Have you read the documentation for CreateInstance[^]? Perhaps this[^] will help.


        Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

        T Offline
        T Offline
        Tavbi
        wrote on last edited by
        #3

        I read, but I still have problem. Can you give me solution for my example, please? thanks

        C 1 Reply Last reply
        0
        • T Tavbi

          I read, but I still have problem. Can you give me solution for my example, please? thanks

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Something like this:

          Type type = Type.GetType("MyNamespace.MyFormName");
          object[] args = new object[1];
          args[0] = new DSBasis();
          Activator.CreateInstance(type, args);


          Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

          T 1 Reply Last reply
          0
          • C Colin Angus Mackay

            Something like this:

            Type type = Type.GetType("MyNamespace.MyFormName");
            object[] args = new object[1];
            args[0] = new DSBasis();
            Activator.CreateInstance(type, args);


            Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

            T Offline
            T Offline
            Tavbi
            wrote on last edited by
            #5

            Thank you Colin, it works.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups