Search code examples
.netwinformssubroutine

a generic dialog load routine


i have alot of dialog in my winform app and i do this for each one of them when i need to load

Dim frm As New Settings
        frm.ShowDialog()
        frm = Nothing

i was thinking if its possible to have a routine like this

sub LoadDialog(byval item as form)
' code to load specific form passd here
end sub

then i call like this loadDialog(customersDialog). where the CustomerDialog is a form

an idea on how to do this?


Solution

  • You can make a generic procedure to handle this:

    Public Shared Sub LoadAndShowDialog(Of T As {Form, New})()
        Dim frm As New T
        frm.ShowDialog() 
    End Function
    

    You could then call this as:

    LoadAndShowDialog(Of Settings)()