ArcObjects Library Reference (Controls)  

IToolbarControl2.Buddy Property

The object that will have its current tool managed by the toolbar.

[Visual Basic .NET]
Public ReadOnly Property Buddy As Object
[C#]
public object Buddy {get;}
[C++]
HRESULT get_Buddy(
  IDispatch** pVal
);
[C++]

Parameters

pVal [out, retval]   pVal is a parameter of type IDispatch*

Product Availability

Available with ArcGIS Engine.

Description

The Buddy returns the object implementing IToolbarBuddy that was passed to the SetBuddyControl method. The Buddy is responsible for handling the CurrentTool.

The SetBuddyControl method will remove any wrapper object that a development environment has added to the control passed to it. As such, the object passed into the SetBuddyControl method may be different from the object returned by the Buddy.

Remarks

When an application is first started the Buddy may return Nothing until the first Update has happened. By default the Update method will be first called internally after an UpdateInterval (the default is 500 milliseconds). To avoid this delay call Update within the form load event.

[C#]
//Determine the Buddy type
if (axToolbarControl1.Buddy != null)
{
  //QI for IMapControl3
  if  (axToolbarControl1.Buddy is IMapControl3)
  {     
    IMapControl3 mapControl = (IMapControl3) axToolbarControl1.Buddy;
  }
  //QI for IPageLayouControl2  
  else if (axToolbarControl1.Buddy is IPageLayoutControl2)
  {
    IPageLayoutControl2 pageLayoutControl = (IPageLayoutControl2) axToolbarControl1.Buddy;
  }
  //QI for ISceneControl  
  else if (axToolbarControl1.Buddy is ISceneControl)
  {
    ISceneControl sceneControl = (ISceneControl) axToolbarControl1.Buddy;
  }
  //QI for IGlobeControl 
  else if (axToolbarControl1.Buddy is IGlobeControl)
  {
    IGlobeControl globeControl = (IGlobeControl) axToolbarControl1.Buddy;
  }
}
[Visual Basic .NET]
'Determine the Buddy type
If Not AxToolbarControl1.Buddy Is Nothing Then
  'QI for IMapControl3
  If TypeOf AxToolbarControl1.Buddy Is ESRI.ArcGIS.Controls.IMapControl3 Then
    Dim pMapControl As ESRI.ArcGIS.Controls.IMapControl3
    pMapControl = AxToolbarControl1.Buddy
  'QI for IPageLayouControl2  
  ElseIf TypeOf AxToolbarControl1.Buddy Is ESRI.ArcGIS.Controls.IPageLayoutControl2 Then
    Dim pPageLayoutControl As ESRI.ArcGIS.Controls.IPageLayoutControl2
    pPageLayoutControl = AxToolbarControl1.Buddy()
  'QI for ISceneControl  
  ElseIf TypeOf AxToolbarControl1.Buddy Is ESRI.ArcGIS.Controls.ISceneControl Then
    Dim pSceneControl As ESRI.ArcGIS.Controls.ISceneControl
    pSceneControl = AxToolbarControl1.Buddy
  'QI for IGlobeControl  
  ElseIf TypeOf AxToolbarControl1.Buddy Is ESRI.ArcGIS.Controls.IGlobeControl Then
    Dim pGlobeControl As ESRI.ArcGIS.Controls.IGlobeControl
    pGlobeControl = AxToolbarControl1.Buddy
  End If
End If

See Also

IToolbarControl2 Interface