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 Basic
  4. Having a form name , how to show this form ?

Having a form name , how to show this form ?

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
5 Posts 5 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.
  • K Offline
    K Offline
    kaiwnyt
    wrote on last edited by
    #1

    Hi, If know a form named "Form1", how to get the form object and show it ? '************************************** Dim myFormName As String="Form1" Dim myFormObject As System.Windows.Forms.Form '... 'How to get myFormObject of "Form1" ? 'How to show "Form1" ? '... '************************************** Thanks kaiwnyt

    L D C O 4 Replies Last reply
    0
    • K kaiwnyt

      Hi, If know a form named "Form1", how to get the form object and show it ? '************************************** Dim myFormName As String="Form1" Dim myFormObject As System.Windows.Forms.Form '... 'How to get myFormObject of "Form1" ? 'How to show "Form1" ? '... '************************************** Thanks kaiwnyt

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try: myFormName.show().


      Extreme Exe

      1 Reply Last reply
      0
      • K kaiwnyt

        Hi, If know a form named "Form1", how to get the form object and show it ? '************************************** Dim myFormName As String="Form1" Dim myFormObject As System.Windows.Forms.Form '... 'How to get myFormObject of "Form1" ? 'How to show "Form1" ? '... '************************************** Thanks kaiwnyt

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You're question and code sample are very confusing and don't lend themselves to an clear explaination of what you're doing. THe best I can tell you without a better description of the problem is:

        Dim myForm As New Form1
        myForm.Show()
        

        Dave Kreskowiak Microsoft MVP - Visual Basic

        1 Reply Last reply
        0
        • K kaiwnyt

          Hi, If know a form named "Form1", how to get the form object and show it ? '************************************** Dim myFormName As String="Form1" Dim myFormObject As System.Windows.Forms.Form '... 'How to get myFormObject of "Form1" ? 'How to show "Form1" ? '... '************************************** Thanks kaiwnyt

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

          Do you mean that you just know the name of the form and you would like to display it? You can try to look in the Forms collection to match the name and display that form, using the Show method. Hope this helps Chandra

          1 Reply Last reply
          0
          • K kaiwnyt

            Hi, If know a form named "Form1", how to get the form object and show it ? '************************************** Dim myFormName As String="Form1" Dim myFormObject As System.Windows.Forms.Form '... 'How to get myFormObject of "Form1" ? 'How to show "Form1" ? '... '************************************** Thanks kaiwnyt

            O Offline
            O Offline
            OldWarhorse
            wrote on last edited by
            #5

            This is not a trivial task. If all you have is the simple form name as a string, then you need to use some sort of Reflection to create an instance of that type, AND you have to use the full name of the type, which is "Namespace.Type". Here's one approach: "Loading Classes on the Fly" http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet10082002.asp Here's a similar way, that does not use a configuration file. I just used the assembly name, which should work, unless you or another developer has placed the forms in a different namespace. Either way, you have to know the namespace of the type. If it happens to be the same as the assembly, which usually it will be, then you're in good shape. If not, you just have to know the namespace, and prepend it to the form name. (And don't forget to use proper exception handling. Do as I say, not as I do.)

            Imports System.Reflection
            Module Module1
            Friend Function GetFormUsingGetType(ByVal formName As String) As Form
            Dim myAssembly As [Assembly] = [Assembly].GetExecutingAssembly
            Dim myForm As Form
            Dim myFormName As String
            Dim myType As Type
            Dim myAssemblyNameObj As AssemblyName = myAssembly.GetExecutingAssembly.GetName
            Dim myAssemblyName As String

            myAssemblyName = myAssemblyNameObj.Name
            myType = myAssembly.GetType(myAssemblyName & "." & formName, True, True)
            myFormName = myType.FullName
            myForm = CType(myAssembly.CreateInstance(myFormName), Form)
            Return myForm
            

            End Function

            Friend Function GetFormUsingActivator(ByVal formName As String) As Form
            Dim myForm As Form
            Dim myFormName As String
            Dim myAssemblyNameObj As AssemblyName = [Assembly].GetExecutingAssembly.GetName
            Dim myAssemblyName As String
            Dim obj As System.Runtime.Remoting.ObjectHandle

            myAssemblyName = myAssemblyNameObj.Name
            myFormName = myAssemblyName & "." & formName
            obj = Activator.CreateInstance(myAssemblyName, myFormName)
            myForm = CType(obj.Unwrap, Form)
            Return myForm
            

            End Function
            End Module

            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