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. Show random Form

Show random Form

Scheduled Pinned Locked Moved C#
databasequestionlounge
4 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.
  • G Offline
    G Offline
    Greeky
    wrote on last edited by
    #1

    In a project, I have 1000 forms. guess you have a string contains a name of a random form. How can u show this form? strFormName ="frmForm274"; ???any method like this ??? ???Form fx= GetForm (strFormName); ??? ???fx.show();??? I aim this for ToolBar Items. I have an Table at database.Table contains Form names. User Selects which buttons will be shown.then when user login to program, i read users toolbaritems, add them to toolbar.But i have to write some code to activate click event to show form.

    R 1 Reply Last reply
    0
    • G Greeky

      In a project, I have 1000 forms. guess you have a string contains a name of a random form. How can u show this form? strFormName ="frmForm274"; ???any method like this ??? ???Form fx= GetForm (strFormName); ??? ???fx.show();??? I aim this for ToolBar Items. I have an Table at database.Table contains Form names. User Selects which buttons will be shown.then when user login to program, i read users toolbaritems, add them to toolbar.But i have to write some code to activate click event to show form.

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      1000?!?!??! :confused: You can go with reflection:

      Form form = (Form)Type.GetType("frmForm274").GetConstructor(new Type[0]).Invoke(new object[0]));

      This code surely would create a new form everytime it is called. If you want to reuse the forms then:

      //some field
      private HashTable _formsHash = new HashTable();
      public Form GetForm(strFormName){
      if (!_formsHash.ContainsKey(strFormName)) {
      _formsHash.Add(strFormName, Type.GetType(strFormName).GetConstructor(new Type[0]).Invoke(new object[0])));
      }
      return (Form)formsHash[strFormName];
      }

      But be careful that holding 1000 forms in memory might become a resource problem :). Just out of interest: What are those 1000 forms for? And who built them?

      G 1 Reply Last reply
      0
      • R Robert Rohde

        1000?!?!??! :confused: You can go with reflection:

        Form form = (Form)Type.GetType("frmForm274").GetConstructor(new Type[0]).Invoke(new object[0]));

        This code surely would create a new form everytime it is called. If you want to reuse the forms then:

        //some field
        private HashTable _formsHash = new HashTable();
        public Form GetForm(strFormName){
        if (!_formsHash.ContainsKey(strFormName)) {
        _formsHash.Add(strFormName, Type.GetType(strFormName).GetConstructor(new Type[0]).Invoke(new object[0])));
        }
        return (Form)formsHash[strFormName];
        }

        But be careful that holding 1000 forms in memory might become a resource problem :). Just out of interest: What are those 1000 forms for? And who built them?

        G Offline
        G Offline
        Greeky
        wrote on last edited by
        #3

        :) u get me wrong. none of the forms at cache. A solution consist of 12 seperate projects. all forms count is about 1000. there is one Main MDI Form Project, others are dll including forms. I wanna add a toolbar to mdi form. But i would like to make it customize by user. Each user can add his/her own short cut buttons to toolbar. Think i use Vs.net envoirenment with just "Standart" and "Layout" toolbar. I can add or remove buttons to each toolbar. In my project I wantto use just one toolbar. And user will choose his/her buttons. I add them to toolbar after login proses. When adding, i must add handler to all buttons. when user click a button, i have to create instance of form which belongs to that button then show.

        R 1 Reply Last reply
        0
        • G Greeky

          :) u get me wrong. none of the forms at cache. A solution consist of 12 seperate projects. all forms count is about 1000. there is one Main MDI Form Project, others are dll including forms. I wanna add a toolbar to mdi form. But i would like to make it customize by user. Each user can add his/her own short cut buttons to toolbar. Think i use Vs.net envoirenment with just "Standart" and "Layout" toolbar. I can add or remove buttons to each toolbar. In my project I wantto use just one toolbar. And user will choose his/her buttons. I add them to toolbar after login proses. When adding, i must add handler to all buttons. when user click a button, i have to create instance of form which belongs to that button then show.

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          Assuming all assemblies are already loaded the first line I posted will do the job:

          Form form = (Form)Type.GetType("frmForm274").GetConstructor(new Type[0]).Invoke(new object[0]));

          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