Creating a toolbar palette that works with the ToolbarControl
The palette in the code example in this topic can be used to draw elements on the PageLayoutControl.
To create a toolbar palette that works with the ToolbarControl, perform the following steps:
Steps 1–3 are typically done when a form loads.
- Create a new ToolbarPaletteClass object as shown in the following code:
//Create a ToolbarPalette.
m_ToolbarPalette=new ToolbarPaletteClass();
[VB.NET] 'Create a ToolbarPalette.
m_ToolbarPalette=New ToolbarPalette
- Use the IToolbarPalette.AddItem method to add new tool items to the palette as shown in the following code:
//Add new items to the ToolbarPalette.
m_ToolbarPalette.AddItem("esriControls.ControlsSelectTool", 0, - 1);
m_ToolbarPalette.AddItem("esriControls.ControlsNewCircleTool", 0, - 1);
m_ToolbarPalette.AddItem("esriControls.ControlsNewCurveTool", 0, - 1);
m_ToolbarPalette.AddItem("esriControls.ControlsNewEllipseTool", 0, - 1);
m_ToolbarPalette.AddItem("esriControls.ControlsNewLineTool", 0, - 1);
m_ToolbarPalette.AddItem("esriControls.ControlsNewPolygonTool", 0, - 1);
m_ToolbarPalette.AddItem("esriControls.ControlsNewRectangleTool", 0, - 1);
m_ToolbarPalette.AddItem("esriControls.ControlsNewFreeHandTool", 0, - 1);
[VB.NET] 'Add new items to the ToolbarPalette.
m_ToolbarPalette.AddItem("esriControls.ControlsSelectTool")
m_ToolbarPalette.AddItem("esriControls.ControlsNewCircleTool")
m_ToolbarPalette.AddItem("esriControls.ControlsNewCurveTool")
m_ToolbarPalette.AddItem("esriControls.ControlsNewEllipseTool")
m_ToolbarPalette.AddItem("esriControls.ControlsNewLineTool")
m_ToolbarPalette.AddItem("esriControls.ControlsNewPolygonTool")
m_ToolbarPalette.AddItem("esriControls.ControlsNewRectangleTool")
m_ToolbarPalette.AddItem("esriControls.ControlsNewFreeHandTool")
- Add the ToolbarPaletteClass object to the ToolbarControl as shown in the following code:
//Add the ToolbarPalette to the ToolbarControl.
axToolbarControl1.AddItem(m_ToolbarPalette, 0, - 1, true, 0,
esriCommandStyles.esriCommandStyleIconAndText);
[VB.NET] 'Add the ToolbarPalette to the ToolbarControl.
AxToolbarControl1.AddItem(m_ToolbarPalette, -1, -1, True, 0, esriCommandStyles.esriCommandStyleIconAndText)
- Use the PopupPalette method on the PageLayoutControl OnMouseDown event to open the palette when the user right-clicks the PageLayoutControl. See the following code:
private void axPageLayoutControl1_OnMouseDown(object sender,
ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e)
{
if (e.button == 2)
{
//Open the palette.
m_ToolbarPalette.PopupPalette(e.x, e.y, axPageLayoutControl1.hWnd);
}
}
[VB.NET] Private Sub AxPageLayoutControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent) Handles AxPageLayoutControl1.OnMouseDown
If e.button=2 Then
'Open the palette.
m_ToolbarPalette.PopupPalette(e.x, e.y, AxPageLayoutControl1.hWnd)
End If
End Sub
Remember to set the PageLayoutControl as the ToolBarControl's buddy.
See Also:
ToolbarControl classIToolbarControl interface
IToolbarPalette interface
IPaletteDef interface
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
ArcGIS for Desktop Basic | |
ArcGIS for Desktop Standard | |
ArcGIS for Desktop Advanced |