Windows Forms

SIS Desktop GisLink Add-In applications can use custom Windows Forms to display information and enable user input. Forms can be either modal or modeless.

A modal form does not allow shifting focus between the form and SIS Desktop in the background. To shift focus back to the Cadcorp SIS Desktop ensure the form is closed.

The Map Window control will not update until given focus; it will simply try to take over focus once the GisLink property is disposed (and set to nothing). Most SIS Desktop dialogs are modal (e.g. Item Properties dialog).

  • Add a new Windows Form to the GisLink Add-In project.
  • The SIS Desktop design is used to add new control items from the toolbox and modify the layout of a form.
  • Change to code view and use a form constructor (Public Sub New()) in order to initialise a new instance of the form class.
  • Imports should be used for the Cadcorp.SIS.GisLink.Library and its constants.

In the following example a ComboBox control has been added to the form. During initialisation in the form constructor the names of all overlays from the current map window will be added as items to this ComboBox.

Imports Cadcorp.SIS.GisLink.Library

Imports Cadcorp.SIS.GisLink.Library.Constants

 

Public Class OverlaysDialog

 

   Public Sub New()

        InitializeComponent()

       Try

           For i = 0 To Loader.SIS.GetInt(SIS_OT_WINDOW, 0, "_nOverlay&") - 1

                CB_Overlays.Items.Add(Loader.SIS.GetStr(SIS_OT_OVERLAY, i, "_name$"))

           Next i

       Catch ex AsException

            MsgBox(ex.ToString)

       End Try

   End Sub

 

End Class

A button (ChangeStatus) is added to the Windows Form dialog.

Double click a form button in the SIS Desktop design view to create a Sub procedure stump for the click event of this button.

Additional code is added to the process to change the status of the overlay which is selected in the ComboBox.

The GisLink property is disposed (and set to nothing) to shift the focus back to the Map Window before the form is closed. This allows the Map Window to redraw with the changed overlay status.

Private Sub ChangeStatus_Click(sender As System.Object, e As System.EventArgs) Handles ChangeStatus.Click

   Try

       Dim status As Integer = Loader.SIS.GetInt(Constants.SIS_OT_OVERLAY, CB_Overlays.SelectedIndex, "_status&")

       Select Case status

           Case Constants.SIS_EDITABLE

               Loader.SIS.SetInt(Constants.SIS_OT_OVERLAY, CB_Overlays.SelectedIndex, "_status&", Constants.SIS_INVISIBLE)

           Case Constants.SIS_VISIBLE

               Loader.SIS.SetInt(Constants.SIS_OT_OVERLAY, CB_Overlays.SelectedIndex, "_status&", Constants.SIS_INVISIBLE)

           Case Constants.SIS_HITTABLE

               Loader.SIS.SetInt(Constants.SIS_OT_OVERLAY, CB_Overlays.SelectedIndex, "_status&", Constants.SIS_INVISIBLE)

           Case Constants.SIS_INVISIBLE

               Loader.SIS.SetInt(Constants.SIS_OT_OVERLAY, CB_Overlays.SelectedIndex, "_status&", Constants.SIS_EDITABLE)

       End Select

       Loader.SIS.Dispose()

       Loader.SIS = Nothing

   Catch ex As Exception

        MsgBox(ex.ToString)

   End Try

End Sub

A SisRibbonButton is added to the SIS Desktop interface. Inside the Sub procedure which is addressed by the SisRibbonButton, a new object is created from the form class and displayed using the ShowDialog method.

If the Cadcorp SIS Desktop GisLink property is not required in a Sub procedure it should be immediately disposed from the object which is created from the SisClickArgs class.

Private Sub ModalDialog(ByVal sender AsObject, ByVal e As SisClickArgs)

    e.Desktop.Dispose()

   Try

       Dim MyModalDialog As New OverlaysDialog()

        MyModalDialog.ShowDialog()

   Catch ex As Exception

   End Try

End Sub

A modeless form allows shifting focus between the form and SIS Desktop in the background. The controls can be used with form showing.

You cannot take over control from the form when the SIS Desktop control is either busy or locked (e.g. another Modal dialog is active). This will cause an error exception from the TakeOver command in the Cadcorp SIS Desktop GisLink property.

If the SIS Desktop GisLink property is used then it must be disposed (and set to nothing) in the form constructor of a modeless dialog.

Sub procedures in a modeless form class can be the same as in a modal form.

Public Sub New()

    InitializeComponent()

    Try

        For i = 0 To Loader.SIS.GetInt(SIS_OT_WINDOW, 0, "_nOverlay&") - 1

            CB_Overlays.Items.Add(Loader.SIS.GetStr(SIS_OT_OVERLAY, i, "_name$"))

        Next i

       Loader.SIS.Dispose()

       Loader.SIS = Nothing

    Catch ex As Exception

        MsgBox(ex.ToString)

    End Try

End Sub

In the GisLink application class, inside the Sub procedure which is addressed by the SisRibbonButton, a new object is created from the form class and displayed as a modeless dialog using the Show method.

If the Cadcorp SIS Desktop GisLink property is not required in a Sub procedure it should be immediately disposed from the object which is created from the SisClickArgs class.

By default the SIS Desktop desktop will be the dominant application window. It is recommended creating the form object for a modeless dialog with the topmost property set to true.

Private Sub ModelessDialog(ByVal sender AsObject, ByVal e As SisClickArgs)

    e.Desktop.Dispose()

   Try

       Dim MyModalDialog As New OverlaysDialogModeless() With {.TopMost = True}

       MyModalDialog.Show()

   Catch ex As Exception

   End Try

End Sub