property ToolBar.RequiredHeight as Long
Indicates the height to fit all elements within the control.

TypeDescription
Long A long expression that specifies the height to fit all elements within the control.
The RequiredHeight property gets the height (in pixels) required by the control all all visible items fit the control's client area. The RequiredWidth property gets the width (in pixels) required by the control all all visible items fit the control's client area.

The following samples show how you can get the required size, so all elements of the control fits its client area

VBA (MS Access, Excell...)

With ToolBar1
	With .Items
		.Add "Item 1"
		.Add "Item 2"
	End With
	.Refresh 
	Debug.Print( .RequiredWidth )
	Debug.Print( .RequiredHeight )
End With

VB6

With ToolBar1
	With .Items
		.Add "Item 1"
		.Add "Item 2"
	End With
	.Refresh 
	Debug.Print( .RequiredWidth )
	Debug.Print( .RequiredHeight )
End With

VB.NET

With Extoolbar1
	With .Items
		.Add("Item 1")
		.Add("Item 2")
	End With
	.Refresh()
	Debug.Print( .RequiredWidth )
	Debug.Print( .RequiredHeight )
End With

VB.NET for /COM

With AxToolBar1
	With .Items
		.Add("Item 1")
		.Add("Item 2")
	End With
	.Refresh()
	Debug.Print( .RequiredWidth )
	Debug.Print( .RequiredHeight )
End With

C++

/*
	Copy and paste the following directives to your header file as
	it defines the namespace 'EXTOOLBARLib' for the library: 'ExToolBar 1.0 Control Library'

	#import <ExToolBar.dll>
	using namespace EXTOOLBARLib;
*/
EXTOOLBARLib::IToolBarPtr spToolBar1 = GetDlgItem(IDC_TOOLBAR1)->GetControlUnknown();
EXTOOLBARLib::IItemsPtr var_Items = spToolBar1->GetItems();
	var_Items->Add(L"Item 1",vtMissing,vtMissing);
	var_Items->Add(L"Item 2",vtMissing,vtMissing);
spToolBar1->Refresh();
OutputDebugStringW( _bstr_t(spToolBar1->GetRequiredWidth()) );
OutputDebugStringW( _bstr_t(spToolBar1->GetRequiredHeight()) );

C++ Builder

Extoolbarlib_tlb::IItemsPtr var_Items = ToolBar1->Items;
	var_Items->Add(L"Item 1",TNoParam(),TNoParam());
	var_Items->Add(L"Item 2",TNoParam(),TNoParam());
ToolBar1->Refresh();
OutputDebugString( PChar(ToolBar1->RequiredWidth) );
OutputDebugString( PChar(ToolBar1->RequiredHeight) );

C#

exontrol.EXTOOLBARLib.Items var_Items = extoolbar1.Items;
	var_Items.Add("Item 1",null,null);
	var_Items.Add("Item 2",null,null);
extoolbar1.Refresh();
System.Diagnostics.Debug.Print( extoolbar1.RequiredWidth.ToString() );
System.Diagnostics.Debug.Print( extoolbar1.RequiredHeight.ToString() );

JScript/JavaScript

<BODY onload='Init()'>
<OBJECT CLASSID="clsid:DDF58CFA-750F-45E0-8A00-CFBE431702E2" id="ToolBar1"></OBJECT>

<SCRIPT LANGUAGE="JScript">
function Init()
{
	var var_Items = ToolBar1.Items;
		var_Items.Add("Item 1",null,null);
		var_Items.Add("Item 2",null,null);
	ToolBar1.Refresh();
	alert( ToolBar1.RequiredWidth );
	alert( ToolBar1.RequiredHeight );
}
</SCRIPT>
</BODY>

VBScript

<BODY onload='Init()'>
<OBJECT CLASSID="clsid:DDF58CFA-750F-45E0-8A00-CFBE431702E2" id="ToolBar1"></OBJECT>

<SCRIPT LANGUAGE="VBScript">
Function Init()
	With ToolBar1
		With .Items
			.Add "Item 1"
			.Add "Item 2"
		End With
		.Refresh 
		alert( .RequiredWidth )
		alert( .RequiredHeight )
	End With
End Function
</SCRIPT>
</BODY>

C# for /COM

EXTOOLBARLib.Items var_Items = axToolBar1.Items;
	var_Items.Add("Item 1",null,null);
	var_Items.Add("Item 2",null,null);
axToolBar1.Refresh();
System.Diagnostics.Debug.Print( axToolBar1.RequiredWidth.ToString() );
System.Diagnostics.Debug.Print( axToolBar1.RequiredHeight.ToString() );

X++ (Dynamics Ax 2009)

public void init()
{
	COM com_Items;
	anytype var_Items;
	;

	super();

	var_Items = extoolbar1.Items(); com_Items = var_Items;
		com_Items.Add("Item 1");
		com_Items.Add("Item 2");
	extoolbar1.Refresh();
	print( extoolbar1.RequiredWidth() );
	print( extoolbar1.RequiredHeight() );
}

Delphi 8 (.NET only)

with AxToolBar1 do
begin
	with Items do
	begin
		Add('Item 1',Nil,Nil);
		Add('Item 2',Nil,Nil);
	end;
	Refresh();
	OutputDebugString( RequiredWidth );
	OutputDebugString( RequiredHeight );
end

Delphi (standard)

with ToolBar1 do
begin
	with Items do
	begin
		Add('Item 1',Null,Null);
		Add('Item 2',Null,Null);
	end;
	Refresh();
	OutputDebugString( RequiredWidth );
	OutputDebugString( RequiredHeight );
end

VFP

with thisform.ToolBar1
	with .Items
		.Add("Item 1")
		.Add("Item 2")
	endwith
	.Refresh
	DEBUGOUT( .RequiredWidth )
	DEBUGOUT( .RequiredHeight )
endwith

dBASE Plus

local oToolBar,var_Items

oToolBar = form.Activex1.nativeObject
var_Items = oToolBar.Items
	var_Items.Add("Item 1")
	var_Items.Add("Item 2")
oToolBar.Refresh()
? Str(oToolBar.RequiredWidth) 
? Str(oToolBar.RequiredHeight) 

XBasic (Alpha Five)

Dim oToolBar as P
Dim var_Items as P

oToolBar = topparent:CONTROL_ACTIVEX1.activex
var_Items = oToolBar.Items
	var_Items.Add("Item 1")
	var_Items.Add("Item 2")
oToolBar.Refresh()
? oToolBar.RequiredWidth 
? oToolBar.RequiredHeight 

Visual Objects

local var_Items as IItems

var_Items := oDCOCX_Exontrol1:Items
	var_Items:Add("Item 1",nil,nil)
	var_Items:Add("Item 2",nil,nil)
oDCOCX_Exontrol1:Refresh()
OutputDebugString(String2Psz( AsString(oDCOCX_Exontrol1:RequiredWidth) ))
OutputDebugString(String2Psz( AsString(oDCOCX_Exontrol1:RequiredHeight) ))

PowerBuilder

OleObject oToolBar,var_Items

oToolBar = ole_1.Object
var_Items = oToolBar.Items
	var_Items.Add("Item 1")
	var_Items.Add("Item 2")
oToolBar.Refresh()
MessageBox("Information",string( String(oToolBar.RequiredWidth) ))
MessageBox("Information",string( String(oToolBar.RequiredHeight) ))

Visual DataFlex

Procedure OnCreate
	Forward Send OnCreate
	Variant voItems
	Get ComItems to voItems
	Handle hoItems
	Get Create (RefClass(cComItems)) to hoItems
	Set pvComObject of hoItems to voItems
		Get ComAdd of hoItems "Item 1" Nothing Nothing to Nothing
		Get ComAdd of hoItems "Item 2" Nothing Nothing to Nothing
	Send Destroy to hoItems
	Send ComRefresh
	Showln (ComRequiredWidth(Self))
	Showln (ComRequiredHeight(Self))
End_Procedure

XBase++

#include "AppEvent.ch"
#include "ActiveX.ch"

PROCEDURE Main
 	LOCAL oForm
	LOCAL nEvent := 0, mp1 := NIL, mp2 := NIL, oXbp := NIL
	LOCAL oItems
	LOCAL oToolBar

	oForm := XbpDialog():new( AppDesktop() )
	oForm:drawingArea:clipChildren := .T.
	oForm:create( ,,{100,100}, {640,480},, .F. )
	oForm:close  := {|| PostAppEvent( xbeP_Quit )}

	oToolBar := XbpActiveXControl():new( oForm:drawingArea )
	oToolBar:CLSID  := "Exontrol.ToolBar.1" /*{DDF58CFA-750F-45E0-8A00-CFBE431702E2}*/
	oToolBar:create(,, {10,60},{610,370} )

		oItems := oToolBar:Items()
			oItems:Add("Item 1")
			oItems:Add("Item 2")
		oToolBar:Refresh()
		DevOut( Transform(oToolBar:RequiredWidth(),"") )
		DevOut( Transform(oToolBar:RequiredHeight(),"") )

	oForm:Show()
	DO WHILE nEvent != xbeP_Quit
		nEvent := AppEvent( @mp1, @mp2, @oXbp )
		oXbp:handleEvent( nEvent, mp1, mp2 )
	ENDDO 
RETURN