Migration to 9.3 Windows forms

Hello,

We are going to migrate from version 9.2 to 9.3. We already know that Windows forms are no longer supported and we have some custom tasks that use it, for example like the code below.

How can we migrate this code to something 9.3 compatible? Is there any guidelines that we can follow in order to migrate this kind of code?
-------------------------------------------------
Using filedlg As New System.Windows.Forms.OpenFileDialog()
filedlg.Title = #LD("Please select the import file for removing SAP roles from a business roles")#
filedlg.InitialDirectory = "c:\"
filedlg.Filter = "csv files (*.csv)|*.csv"
filedlg.FilterIndex = 1
filedlg.RestoreDirectory = True

While True
If filedlg.ShowDialog() <> DialogResult.Ok Then
Return
Else
Exit While
End If
End While
-------------------------------------------------

Thanks in advance.

David.

Parents
  • Hi David,

    you need to move your Windows Forms Code from the Dialog Scripts into a Windows Forms Class library project.  For example use Visual Studio or Visual Studio Code to do so. The result should be a  DLL and you need to target .NET 8.0 platform Windows to make it work.

    You can then load this assembly (late bind) in your DialogMethod code.

    Some sample code from such a DialogMethod. It loads the WinForm CCC_PersonMagicNumber (Class CCC_PersonMagicNumber, Namespace SDK_WinForms_Sample in the assembly) from the assembly SDK_WinForms_Sample.dll.

    '########################
    'DialogMethod sample code
    '########################
    'Latebind: <Namespace>.<Class name>, <name of dll file without extension>
    Dim formType = VI.Base.AssemblyLoader.GetType("SDK_WinForms_Sample.CCC_PersonMagicNumber, SDK_WinForms_Sample")
    'Create instance  of the class
    'Sample shows how to pass parameters Session and base object (optional)
    Dim form = Activator.CreateInstance(formType, {Session, Base.GetEntity()})
    'Call method ShowDialog
    Dim result = formType.GetMethod("ShowDialog", Array.Empty(Of Type)()).Invoke(form, Nothing)
    'Check result
    If result.ToString().ToUpper() = "OK" Then
    	'Read parameter from WinForm using reflection
    	Dim myMagicNumber As String = form.GetType().GetProperty("myMagicNumber").GetValue(form).ToString()
    	MsgBox(myMagicNumber, LanguageDependent("DialogMethod", "MethodScript", "CAUTION"), MsgBoxButtons.YesNo, MsgBoxIcon.Question)
    Else
    	Exit Sub
    End If

    Sample Code from the CCC_PersonMagicNumber class (without the WinForms Designer code). My sample references the two DLLs VI.Base.dll and VI.DB.dll directly to make it work, Remember, it is a sample.

    Imports VI.DB.Entities
    
    Public Class CCC_PersonMagicNumber
        Dim mySession As ISession
        Dim myEntBase As IEntity
        Public Sub New(ByVal Session As ISession, ByVal EntBase As IEntity)
            'Initalisiert das Form wenn es erstellt wird
            InitializeComponent()
            mySession = Session
            myEntBase = EntBase
        End Sub
        Public Property Session() As ISession
            Get
                Return mySession
            End Get
            Set(ByVal value As ISession)
                mySession = value
            End Set
        End Property
    
        Public Property EntBase() As IEntity
            Get
                Return myEntBase
            End Get
            Set(ByVal value As IEntity)
                myEntBase = value
            End Set
        End Property
    
        Public Property myMagicNumber() As String
            Get
                Return TextBoxMagicNumber.Text.ToString
            End Get
            Set(ByVal Value As String)
            End Set
        End Property
    
    End Class

Reply
  • Hi David,

    you need to move your Windows Forms Code from the Dialog Scripts into a Windows Forms Class library project.  For example use Visual Studio or Visual Studio Code to do so. The result should be a  DLL and you need to target .NET 8.0 platform Windows to make it work.

    You can then load this assembly (late bind) in your DialogMethod code.

    Some sample code from such a DialogMethod. It loads the WinForm CCC_PersonMagicNumber (Class CCC_PersonMagicNumber, Namespace SDK_WinForms_Sample in the assembly) from the assembly SDK_WinForms_Sample.dll.

    '########################
    'DialogMethod sample code
    '########################
    'Latebind: <Namespace>.<Class name>, <name of dll file without extension>
    Dim formType = VI.Base.AssemblyLoader.GetType("SDK_WinForms_Sample.CCC_PersonMagicNumber, SDK_WinForms_Sample")
    'Create instance  of the class
    'Sample shows how to pass parameters Session and base object (optional)
    Dim form = Activator.CreateInstance(formType, {Session, Base.GetEntity()})
    'Call method ShowDialog
    Dim result = formType.GetMethod("ShowDialog", Array.Empty(Of Type)()).Invoke(form, Nothing)
    'Check result
    If result.ToString().ToUpper() = "OK" Then
    	'Read parameter from WinForm using reflection
    	Dim myMagicNumber As String = form.GetType().GetProperty("myMagicNumber").GetValue(form).ToString()
    	MsgBox(myMagicNumber, LanguageDependent("DialogMethod", "MethodScript", "CAUTION"), MsgBoxButtons.YesNo, MsgBoxIcon.Question)
    Else
    	Exit Sub
    End If

    Sample Code from the CCC_PersonMagicNumber class (without the WinForms Designer code). My sample references the two DLLs VI.Base.dll and VI.DB.dll directly to make it work, Remember, it is a sample.

    Imports VI.DB.Entities
    
    Public Class CCC_PersonMagicNumber
        Dim mySession As ISession
        Dim myEntBase As IEntity
        Public Sub New(ByVal Session As ISession, ByVal EntBase As IEntity)
            'Initalisiert das Form wenn es erstellt wird
            InitializeComponent()
            mySession = Session
            myEntBase = EntBase
        End Sub
        Public Property Session() As ISession
            Get
                Return mySession
            End Get
            Set(ByVal value As ISession)
                mySession = value
            End Set
        End Property
    
        Public Property EntBase() As IEntity
            Get
                Return myEntBase
            End Get
            Set(ByVal value As IEntity)
                myEntBase = value
            End Set
        End Property
    
        Public Property myMagicNumber() As String
            Get
                Return TextBoxMagicNumber.Text.ToString
            End Get
            Set(ByVal Value As String)
            End Set
        End Property
    
    End Class

Children
No Data