ArcObjects Library Reference

Customize ToolbarControl Snippet

Use the customize dialog to modify a ToolbarControl.

[C#]

// summary: Use the customize dialog to modify a ToolbarControl.
//
// remarks: This snippet assumes a ToolbarControl is embedded into a container.

// The ToolbarControl
public ESRI.ArcGIS.Controls.IToolbarControl m_ToolbarControl;

//The CustomizeDialog used by the ToolbarControl
public ESRI.ArcGIS.Controls.ICustomizeDialog m_CustomizeDialog;

//The CustomizeDialog start event
public ESRI.ArcGIS.Controls.ICustomizeDialogEvents_OnStartDialogEventHandler startDialogE;

//The CustomizeDialog close event 
public ESRI.ArcGIS.Controls.ICustomizeDialogEvents_OnCloseDialogEventHandler closeDialogE;

// Call to create the CustomizeDialog and wire its events
// For example, if a ToolbarControl named axToolbarControl1 exists use the following code:
// CreateCustomizeDialog(axToolbarControl1.Object as ESRI.ArcGIS.Controls.IToolbarControl);
// To display the CustomizeDialog and customize the ToolbarControl use the following code:
// m_CustomizeDialog.StartDialog(m_ToolbarControl.hWnd);
public void CreateCustomizeDialog(ESRI.ArcGIS.Controls.IToolbarControl toolbarControl)
{
  //Set the ToolbarControl
  m_ToolbarControl = toolbarControl;

  //Create new customize dialog 
  m_CustomizeDialog = new ESRI.ArcGIS.Controls.CustomizeDialogClass();

  //Set the title
  m_CustomizeDialog.DialogTitle = "Customize ToolbarControl Items";

  //Show the 'Add from File' button
  m_CustomizeDialog.ShowAddFromFile = true;

  //Set the ToolbarControl that new items will be added to
  m_CustomizeDialog.SetDoubleClickDestination(m_ToolbarControl);

  //Set the customize dialog events 
  startDialogE = new ESRI.ArcGIS.Controls.ICustomizeDialogEvents_OnStartDialogEventHandler(OnStartDialog);
  ((ESRI.ArcGIS.Controls.ICustomizeDialogEvents_Event)m_CustomizeDialog).OnStartDialog += startDialogE;

  closeDialogE = new ESRI.ArcGIS.Controls.ICustomizeDialogEvents_OnCloseDialogEventHandler(OnCloseDialog);
  ((ESRI.ArcGIS.Controls.ICustomizeDialogEvents_Event)m_CustomizeDialog).OnCloseDialog += closeDialogE;
}

public void OnStartDialog()
{
  //Put the ToolbarControl into customize mode
  m_ToolbarControl.Customize = true;
}

public void OnCloseDialog()
{
  //Take the ToolbarControl out of customize mode
  m_ToolbarControl.Customize = false;
}
[Visual Basic .NET]

' summary: Use the customize dialog to modify a ToolbarControl.
'
' remarks: This snippet assumes a ToolbarControl is embedded into a container.

' The ToolbarControl
Private m_ToolbarControl As ESRI.ArcGIS.Controls.IToolbarControl

' The CustomizeDialog used by the ToolbarControl
Private m_CustomizeDialog As ESRI.ArcGIS.Controls.ICustomizeDialog

' The CustomizeDialog start event
Private startDialogE As ESRI.ArcGIS.Controls.ICustomizeDialogEvents_OnStartDialogEventHandler

' The CustomizeDialog close event 
Private closeDialogE As ESRI.ArcGIS.Controls.ICustomizeDialogEvents_OnCloseDialogEventHandler

' Call to create the CustomizeDialog and wire its events
' For example, if a ToolbarControl named AxToolbarControl1 exists use the following code:
' CreateCustomizeDialog(AxToolbarControl1.Object)
' To display the CustomizeDialog and customize the ToolbarControl use the following code:
' m_CustomizeDialog.StartDialog(m_ToolbarControl.hWnd)
Private Sub CreateCustomizeDialog(ByVal toolbarControl As ESRI.ArcGIS.Controls.IToolbarControl)

  'Set the ToolbarControl
  m_ToolbarControl = toolbarControl

  'Create new customize dialog 
  m_CustomizeDialog = New ESRI.ArcGIS.Controls.CustomizeDialogClass()

  'Set the title
  m_CustomizeDialog.DialogTitle = "Customize ToolbarControl Items"

  'Show the 'Add from File' button
  m_CustomizeDialog.ShowAddFromFile = True

  'Set the ToolbarControl that new items will be added to
  m_CustomizeDialog.SetDoubleClickDestination(toolbarControl)

  'Set the customize dialog events 
  startDialogE = New ESRI.ArcGIS.Controls.ICustomizeDialogEvents_OnStartDialogEventHandler(AddressOf OnStartDialog)
  AddHandler CType(m_CustomizeDialog, ESRI.ArcGIS.Controls.ICustomizeDialogEvents_Event).OnStartDialog, startDialogE

  closeDialogE = New ESRI.ArcGIS.Controls.ICustomizeDialogEvents_OnCloseDialogEventHandler(AddressOf OnCloseDialog)
  AddHandler CType(m_CustomizeDialog, ESRI.ArcGIS.Controls.ICustomizeDialogEvents_Event).OnCloseDialog, closeDialogE
End Sub

Private Sub OnStartDialog()

  'Put the ToolbarControl into customize mode
  m_ToolbarControl.Customize = True

End Sub

Private Sub OnCloseDialog()

  'Take the ToolbarControl out of customize mode
  m_ToolbarControl.Customize = False

End Sub


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Controls
  • ESRI.ArcGIS.Display
  • ESRI.ArcGIS.System