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. Generate a form by using form name as string

Generate a form by using form name as string

Scheduled Pinned Locked Moved C#
questionalgorithms
5 Posts 4 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.
  • A Offline
    A Offline
    ayca
    wrote on last edited by
    #1

    Hi all, I have a name of a windows form in string type. I would like to generate it in runtime. How can I succeed this? ex: //my form class is MainPage let's say. //I have : string nameOfPage = "MainPage"; //I am searching a way of generating a form of type MainPage by just using variable nameOfPage Thanks a lot!

    T C 2 Replies Last reply
    0
    • A ayca

      Hi all, I have a name of a windows form in string type. I would like to generate it in runtime. How can I succeed this? ex: //my form class is MainPage let's say. //I have : string nameOfPage = "MainPage"; //I am searching a way of generating a form of type MainPage by just using variable nameOfPage Thanks a lot!

      T Offline
      T Offline
      Tarakeshwar Reddy
      wrote on last edited by
      #2

      Create an object of the form and set the name of the object as MainPage

      Form newForm = new Form();
      newForm.Name = "frmMainPage";
      newForm.Size = new Size(200, 200);
      newForm.Location = new Point(10, 10);
      newForm.Show();
      Oops I read your question wrong:sigh:. You must be using what Colin said

      Last modified: 11mins after originally posted --

      C 1 Reply Last reply
      0
      • A ayca

        Hi all, I have a name of a windows form in string type. I would like to generate it in runtime. How can I succeed this? ex: //my form class is MainPage let's say. //I have : string nameOfPage = "MainPage"; //I am searching a way of generating a form of type MainPage by just using variable nameOfPage Thanks a lot!

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

        A form is just a class. You can use reflection to instantiate an object of a class if you know the name of the class. See the MSDN documentation in the System.Reflection namespace.


        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

        1 Reply Last reply
        0
        • T Tarakeshwar Reddy

          Create an object of the form and set the name of the object as MainPage

          Form newForm = new Form();
          newForm.Name = "frmMainPage";
          newForm.Size = new Size(200, 200);
          newForm.Location = new Point(10, 10);
          newForm.Show();
          Oops I read your question wrong:sigh:. You must be using what Colin said

          Last modified: 11mins after originally posted --

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          IMHO this is not OP asks.:confused: Perhaps he wants to dynamically create an instance of a class whose type is given by the "frmMainPage" string. Do you agree? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          T 1 Reply Last reply
          0
          • C CPallini

            IMHO this is not OP asks.:confused: Perhaps he wants to dynamically create an instance of a class whose type is given by the "frmMainPage" string. Do you agree? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            T Offline
            T Offline
            Tarakeshwar Reddy
            wrote on last edited by
            #5

            CPallini wrote:

            Perhaps he wants to dynamically create an instance of a class whose type is given by the "frmMainPage" string. Do you agree?

            Yeah, realized I read his question wrong

            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