Windows forms does not work in ArcGIS Add-ins

1992
2
04-02-2011 12:37 PM
Highlighted
New Contributor
Hi,

I am trying to use load forms in Add-ins, but it doesnt work. If anyone have any idea please help.

Thanks,

Ahmad
0 Kudos
2 Replies
Highlighted
New Contributor II
Hi,
you can create forms writing some code. Using VB you can start with something like this:
Dim myForm As New Windows.Forms.Form
Dim myCombo As New Windows.Forms.ComboBox
Dim myCreate As New Windows.Forms.Button
myForm.StartPosition = FormStartPosition.CenterScreen
myForm.Height = 110
myForm.Width = 150
...
0 Kudos
Highlighted
New Contributor
Hi Ahmad,

To open or load a windows form in ArcGIS 10 add-ins, you need to make the following changes to the class module that is created with the add-in.  This example shows how to open a windows form from a button add-in.

In the class module, create a class-level variable:

>> Private myForm As New frmMain

In the OnClick event, add the following code:

>> myForm = New frmMain
>> myForm.Show()           ' to open the form as modeless window
>> 'myForm.ShowDialog()  ' to open the form as modal window

In my code below, I first check to see if the window is already open before I call the code to open the form.

>> If myForm IsNot Nothing AndAlso myForm.Visible = False Then


-------------------------------------------------------------------------------

Public Class Test_Button
  Inherits ESRI.ArcGIS.Desktop.AddIns.Button

    Private myForm As New frmMain

    Public Sub New()

    End Sub

    Protected Overrides Sub OnClick()
        If myForm IsNot Nothing AndAlso myForm.Visible = False Then
            myForm = New frmMain
            myForm.Show()        ' to open the form as modeless window
            'myForm.ShowDialog()  ' to open the form as modal window
        End If
    End Sub

  Protected Overrides Sub OnUpdate()
    Enabled = My.ArcMap.Application IsNot Nothing
  End Sub

End Class


Hi,

I am trying to use load forms in Add-ins, but it doesnt work. If anyone have any idea please help.

Thanks,

Ahmad
0 Kudos