Sdílet prostřednictvím


Form methods

Forms provide the following methods:

  • AddMenuHandler()
  • Close()
  • Dispose()
  • Open()

AddMenuHandler()

The AddMenuHandler() method adds a menu item to the "Additional" menu that appears in windows in Microsoft Dynamics GP. The menu item will be available when the form is open. This method takes three parameters:

EventHandler - The function that will be run when the menu item is chosen in Microsoft Dynamics GP.

MenuItemName - A string containing the text that will be displayed for the menu item.

AcceleratorKey - A string containing a single character that will be used as the accelerator key for the menu item. Be sure this accelerator key does not conflict with any existing accelerator keys. If you don't want an accelerator key, use the empty string.

The following C# example shows how a menu handler for the "Estimate Freight" menu item is added to the SopEntry form in Microsoft Dynamics GP:

Dynamics.Forms.SOPEntry.AddMenuHandler(OpenEstimateFreight,
"Estimate Freight", "F");

This code is the event handler for the menu item. Notice that it takes two arguments like standard event handlers.

static void OpenEstimateFreight(object sender, EventArgs e)
{
    if (EstimateFreightForm == null)
    {
        EstimateFreightForm = new EstimateFreight();
    }
    else
    {
        if (EstimateFreightForm.Created == false)
        {
            EstimateFreightForm = new EstimateFreight();
        }
    }

    // Always show and activate the WinForm
    EstimateFreightForm.Show();
    EstimateFreightForm.Activate();
    }
}

The following Visual Basic example shows how the same menu handler for the "Estimate Freight" menu item is added to the SopEntry form in Microsoft Dynamics GP.

Dim EstimateFreightHandler as System.EventHandler

EstimateFreightHandler = New System.EventHandler(AddressOf OpenEstimateFreight)
Dynamics.Forms.SOPEntry.AddMenuHandler(EstimateFreightHandler, "Estimate Freight", "F")

This code is the event handler for the menu item. Notice that it also takes two arguments like standard event handlers.

Shared Sub OpenEstimateFreight(ByVal sender As Object, ByVal e As EventArgs)
    If EstimateFreightForm Is Nothing Then
        Try
            EstimateFreightForm = New EstimateFreightForm()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    Else
        If EstimateFreightForm.Created = False Then
            EstimateFreightForm = New EstimateFreightForm()
        End If
    End If

    ' Always show and activate the WinForm
    EstimateFreightForm.Show()
    EstimateFreightForm.Activate()
End Sub

Close()

The Close() method closes the form.

Dispose()

The Dispose() method releases the memory used for the form after it is no longer needed.

Open()

The Open() method attempts to open the form.