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. Visual Studio
  4. Dynamically selecting a form [modified]

Dynamically selecting a form [modified]

Scheduled Pinned Locked Moved Visual Studio
csharpdatabasetutorialquestion
2 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.
  • L Offline
    L Offline
    lvandevyvere
    wrote on last edited by
    #1

    Hi there, In my VS2008 project, I start with a form used as a switchboard: 8 buttons and labels are placed on the form, and the textproperty of the labels is filled according to values found in a database. The table in that database holds the text to be displayed, as well as the name of the form to be opened when the corresponding button is clicked. How should I write my code so that the appropiate form is opened, without using a 'Select Case' or 'If Then Else', but by using the forms name as argument ? I'm using VB.Net, but an example in C# is also appreciated. Thanks in advance.

    modified on Thursday, May 8, 2008 7:00 AM

    L 1 Reply Last reply
    0
    • L lvandevyvere

      Hi there, In my VS2008 project, I start with a form used as a switchboard: 8 buttons and labels are placed on the form, and the textproperty of the labels is filled according to values found in a database. The table in that database holds the text to be displayed, as well as the name of the form to be opened when the corresponding button is clicked. How should I write my code so that the appropiate form is opened, without using a 'Select Case' or 'If Then Else', but by using the forms name as argument ? I'm using VB.Net, but an example in C# is also appreciated. Thanks in advance.

      modified on Thursday, May 8, 2008 7:00 AM

      L Offline
      L Offline
      LongRange Shooter
      wrote on last edited by
      #2

      I've frequently written code where an action relates to a class to be executed. Your process is similar. So let's assume that all of your forms are compiled into a separate assembly: Mycompany.Myapplication.DynamicFormsAssembly.dll and the dll name matches the assembly name.

              void ShowDynamicForm( System.Windows.Forms.Label sender )
              {
                  Assembly assembly = Assembly.GetAssembly( typeof( Mycompany.Myapplication.DynamicFormsAssembly ) );
                  Form dynamicForm = ( Form )assembly.CreateInstance( sender.TextProperty );
                  dynamicForm.Parent = this;
                  dynamicForm.Show();
              }
      

      Good luck doing this in VB.

      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