Form manager class


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi,

Since I am really new to .NET I can get too deep into the discussion, but as a developer in general, all I want to see in the framework are those little things that has to be done in each project and that will take a lot of time to do all over again.

I have to admit that being working with a VFP framework may have spoiled me a little, but when is time to start a new project I don't want to have to remember to manually create classes all over again. Hehe

Edhy Rijo

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
That's a good point Greg... everyone uses the scheme, but everyone also customizes it.  A template wouldn't be a bad idea.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I wonder if this should be part of the framework (i.e. one of the classes included in the framework). I just seeing a zillion variations on the theme, so much so that I wonder how much something like this would actually get used. I know I use constructors of forms a lot to pass in required initial data that is needed to load the data on the form.



However, what about making a template for this? Then there could be a new SF MenuSystem object that you could add to the project. This is a very nice starting point for all of those variations. Just a thought...
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
I have seen many post about the same thing, how to launch a form and have some control over the process.  Trent and others has made some very nice suggestion like the one below. 

I think that this type of functionality should be included in the SF framework itself, since 99% of projects based on SF will have to launch at least one form, this functionality definately should be part of the framework.

Trent L. Taylor (06/07/2007)
You can do that, but you first need to have a centralized collection that can be referenced.  You are actually better off doing this outside of the instantiaion for one primary reason...speed and maintainability...OK, that is two reasons Smile  We created a shared class called MenuSystem which houses all of our instantiation logic.  Security, form collections, multiple-instances, and whether the form will appear in the MDI window or on its own, all within one central location.  Ours had to be a bit more specialized since it can launch VFP forms or .NET forms.  But the logic is basically the same.

You could even create a class that is passed to the MenuSystem that has all of the logic that you need that you could pass over....or just create a bunch of overloads to do this for you.  It is just up to you, but the key is creating a class that launches all of your forms according to your environment and needs.

Public Notineritable Class MenuSystem

Private Shared _MenuMdiClient As MDIClient
Private Shared _Forms As New System.Collections.Generics.List(Of SYstem.Windows.Forms.Form)

'-- Reference to the MDI client to which all client forms will be added.  Be sure to set this in your
'    New of the parent that houses the MDI client.
Public SHared Property MenuMdiClient As MDIClient
    Get
        Return _MenuMdiClient
    End Get
    Set(Byval value as MdiClient)
        _MenuMdiClient = value
    End Set
End Property

'-- This collection contains all of the forms that are loaded
Public Shared Readonly Property Forms As System.Collections.Generics.List(Of System.Windows.Forms.Form)
    Get
         Return _Forms
    End Get
End Property

'-- Central method to load all of the
Public Shared Sub LaunchForm(ByVal FormType As System.Type, Byval SecurityKey As String, Byval SingleInstance As Boolean)
    '-- Establish Locals
    Dim loForm As System.WIndows.Forms.Form

    If SecurityBasics.CurrentUser.GetPermission(SecurityKey).Action = Grant Then
       '-- Check for a single instance
       If SingleInstance AndAlso FormIsRunning(FormType) Then
            Exit Sub
       End If

       '-- Create and launch the form
        loForm = CType(Activator.CreateInstance(FormType), System.WIndows.Forms.Form)
        loForm.MdiParent = _MenuMdiClient

        '-- Create a handler so it can remove itself from the collection
        AddHandler loForm.FormClosed, Addressof HandleFormClosed

        loForm.Show()
    End If

   Private Shared Function FormIsRunning(Byval FormType As System.Type) As Boolean
     Dim llReturn As Boolean = False

      For Each loForm As Form In _Forms
         If loForm.GetType() Is FormType Then
             llReturn = True
             Exit For
         End If
      Next

      Return llReturn
    End Function

    Private Shared Sub HandleFormClosed(Byval sender as Object, Byval e as System.EventArgs)
         _Forms.Remove(CType(sender, Form))
    End Sub

End Class



Edhy Rijo

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