StrataFrame Forum

Runing a form from the MainForm menu

http://forum.strataframe.net/Topic511.aspx

By Ivan George Borges - 2/3/2006

Hi guys.

Right, created the database in SQL, the SF application, the BOs for the tables, the SFMaintenanceForms for them, and now the SFappMainForm. Look, all of this new for me.

I'm wandering what code to use in the SFMainForm menu strip item to call the forms. Will I use a SF method for this ? Not using the ToolStrip yet ...

Thanks in advance.

Ivan

By StrataFrame Team - 2/3/2006

Hehe, no problem, Ivan... it can get pretty complex just showing the forms (which at first seems like something simple). Here's some generic code we use within our forms to show the child (MDI) forms.



'''

''' Show a form

'''


'''

'''

Public Sub ShowForm(ByVal FormType As System.Type)

   Me.ShowForm(FormType, Nothing)

End Sub



'''

''' Show a form

'''


'''

'''

Public Sub ShowForm(ByVal FormType As System.Type, ByVal ParamArray Parameters() As Object)

   '-- Establish Locals

   Dim loForm As Object

   Dim llFound As Boolean



   '-- Make sure the form is not currently open

   For Each loForm In Me.MdiChildren

      If loForm.GetType() Is FormType Then

         '-- The form is already shown, so just activate it

         CType(loForm, Form).Activate()

         llFound = True

      End If

   Next



   If Not llFound Then

      If Parameters Is Nothing Then

         loForm = Activator.CreateInstance(FormType)

      Else

         loForm = Activator.CreateInstance(FormType, Parameters)

      End If

   

      With CType(loForm, MicroFour.StrataFrame.UI.Windows.Forms.BaseForm)

         .MdiParent = Me

         .Show()

      End With

   End If

End Sub



Say you have a child form called Form2, then to show it, you would call ShowForm(GetType(Form2)). If you need to pass parameters to the constructor, that's what the second overload is for.



Lemme know if you need this in C#... I can't remember your language (I know it's Portuguese, but I'm talking C#/VB Smile)
By Ivan George Borges - 2/3/2006

Thanks for the help Ben.
Well, to be honest, is there a "sign language" in .NET ?  BigGrin
By StarkMike - 4/26/2006

Where would the code Ben supplied go? In the MDI Parent form or in each of the children?
By StrataFrame Team - 4/26/2006

That code goes in the MDI parent, not the children. So, you can easily show the child forms without having to copy the code to each of them.
By StarkMike - 4/26/2006

Would you guys happen to have an MDI sample in VB .NET that I could download and inspect? I guess I want to use as much of your framework as possible and utilize all the power it contains. I want to avoid doing things the "long" way or the "hard" way. BigGrin
By StrataFrame Team - 4/26/2006

That code (or something very similar to it) should be in the StrataFrame VB.NET sample within your program files. In the MainForm.vb file, is the MDI form where you should find the code.