Open a form - simple Not!


Author
Message
Ben Hayat
Ben Hayat
Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
I just went thru that in C# and GetType (that is used in VB) threw me off until Ben (Chase) came to rescue.

..ßen
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yep, the link that Mike pointed you to is correct... you'll need to use Type.GetType() and pass the full name of the form you want to show.  So, something like this:

DirectCast(Activator.CreateInstance(Type.GetType(FormName)), Form).Show()

The Type.GetType() is a method that accepts a string name for the form (i.e.: "MyNamespace.MyFormName") and returns the System.Type for that form.  The Activator.CreateInstance() accepts a type and creates a new instance of it through reflection to find the default constructor.  The DirectCast just CTypes the returned object as a Form, and Show() is pretty self explanatory. 

So, the only change you'll need to make is to change the FormName that you're storing off in DevEx's menu from just "Form1" to "MyNamespace.Form1" so that you will have the full type name of the form you want to show.

StarkMike
StarkMike
Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)Advanced StrataFrame User (738 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Peter, I too had trouble with this once... here's the help i received...



http://forum.strataframe.net/Topic8063-14-1.aspx



You'd think there SHOULD be an easier way to do this. Oh well.
Peter Jones
Peter Jones
Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi,

No doubt there is an easy solution to this but after serveral hours and failing to find it why not ask the experts? I have a project that contains a meu form (DevExpress NavBar) which is populated from the database. So, I click on an item and I now have a form name which I want to open. Here's the hard part - I can't find any way to iterate through all the forms in my project and .Show the right one, i.e. I can find a forms collection (open forms I can see but not all the forms in my project). I'm just about ready to write a large Case statement to, e.g

Select Case FormName
 Case "Form1"
          My.Forms.Form1.Show()
 Case "Form2"
          My.Forms.Form2.Show()

but obviously I don't want to do that. What's the best way of doing things?

Cheers, Peter

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search