Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to convert my string variable in Windows Form object
Because I want to call Form.Show() method and form name is in variable.

Thanks in advance
Posted

You should have a look at my.application.openforms[^]

There is a good example in the article, but that is if the form is already open

If not then this code snippet will help

VB
Public Function GetForm(ByVal Formname As String) As Form
        Dim t As Type = Type.GetType(Formname) ', True, True)
        If t Is Nothing Then
            Dim Fullname As String = Application.ProductName & "." & Formname
            t = Type.GetType(Fullname, True, True)
        End If
        Return CType(Activator.CreateInstance(t), Form)

    End Function
 
Share this answer
 
v2
Comments
SachinPt 18-Oct-11 11:31am    
Thanks Simon_Whale .....Ur Code Really Works
Why are you storing form name in string? You don't want to do that. You can directly call the from.Show() method.
 
Share this answer
 
Having a variable string from which you determine what form to open doesn't sound like a good idea to me.

Why not have some enumerated types from which the user can select which then determines which form to open?
 
Share this answer
 
You cannot 'convert' a String to a Form Object, however you may find if one of the available forms has the name matching the provided string (and then call the Show method of the found one).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900