Managing the Properties of the TToolbox Panel

Article Details
URL: http://support.radar-soft.net/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=60
Article ID: 60
Created On: 27 Nov 2008 05:36 PM

Answer

Adding Custom Buttons

The TOLAPControlGeneralfont..Toolbox property provides an access to the panel of tools buttons of the Grid.
The example shows how to add a button called "Sample Button" with the Sample_EventHandler to the set of panel’s buttons.

ToolStripButton sampleButton = new ToolStripButton();
sampleButton.Text = "Sample button";
sampleButton.Click += new EventHandler(Sample_EventHandler);
GridTable.Toolbox.Items.Add(sampleButton);

Toolbox with the added button

Managing the Buttons’ Properties

To manage the buttons’ property, you need to specify the TOLAPControlGeneral.ShowToolboxButton event handler, make sure that its e.ItemType argument’s field contains the button’s code (type), and change the appropriate property, available through e.Item.

This event handler is executed when it is assigned (the first call) and upon changing the Grid state.

Example:
The example code makes the PrintPreview and ZoomGroup buttons unavailable and hides the Palette, Skin and PanelsGroup buttons.

GridTable.ShowToolboxButton += new
ShowToolboxButtonEventHandler(GridChart_ShowToolboxButton);

void GridChart_ShowToolboxButton(object sender, ShowToolboxButtonEventArgs e)
{
switch (e.ItemType)
{
case ToolboxButtons.PrintPreview:
case ToolboxButtons.ZoomGroup:
e.Item.Visible = true;
e.Item.Enabled = false;
break;
case ToolboxButtons.ApplyPalette:
case ToolboxButtons.ApplySkin:
case ToolboxButtons.PanelsGroup:
e.Item.Visible = false;
break;
}
}

Standard view of the toolbox.

The view of the toolbox after using the event handler.

To refresh the buttons’ properties, you need to call the TOLAPControlGeneral.RefreshToolboxItems() manually. This will cause the execution of the TOLAPControlGeneral.ShowToolboxButton event handler for all the Grid’s buttons.

Calling the Toolbox Commands

The toolbox commands are called through the TOLAPControlGeneral.ToolboxCallCommand(ToolboxButtons AButtons) method with the button’s code (type) passed as a parameter. If the call is successful, the method returns true.

Example: calling the print preview command

GridTable.ToolboxCallCommand(ToolboxButtons.PrintPreview);

Placing the Toolbox Outside the Grid

You can use the toolbox separately from the Grid; that is place on the form an external toolbox as a separate component and set the TToolbox.Grid property (without this property toolbox buttons will be unavailable).
At that, the properties of toolbox buttons will be amended according to the Grid’s settings and its internal toolbox will be hidden. To restore the latter, you need to set the former’s Grid property to null. This will make the external toolbox buttons visible, but unavailable.
The same way a single toolbox may be used with several Grids, connected in turn to each selected Grid.

The view of an external toolbox, not connected to the Grid.

The view of an external toolbox, connected to the Grid.