The Chart Component .NET contains lot of localizable resources that can be used within your application code. For example, it contains texts in different languages for the enumerations are used to configure the chart layout. You can use these resources in your application. This sample demonstrates how the local texts for the ChartType and LegendPlacement enumerations can be used in the application toolbar.
At the first you need add 2 ToolstripDropDownButtons to your application ToolStrip. Let it be tsddbChartType for the chart types and tsddbLegendPlacement for the legend placement
Now we should get access to the internal Chart Component .NET resources:
// Get chart control resources ResourceManager loCharResources = new ResourceManager("Manco.Chart.Properties.Resources", typeof(Manco.Chart.ChartControl).Assembly); ResourceManager loChartMessages = new ResourceManager("Manco.Chart.Resources.Messages", typeof(Manco.Chart.ChartControl).Assembly);
The first resource manager (loCharResources) allows you using Chart Component .NET images in your application. The second one (loChartMessages) allows using localized Chart Component .NET texts in your application.
The static class ChartUtility contains static methods that allows transform any enumeration to the List<EnumerationValue> that can be used for data binding with any windows forms or web control that supports data binding (for example, combo box). The EnumerationValue object contains enumeration values itself as well as their representation as local text.
// Get the list of the chart types. The name of the chart type // will be localized if desirable local is available List<EnumerationValue> loChartTypeList = ChartUtility.ConvertEnumForBinding(typeof(ChartType), loChartMessages); // Get the list of the legend placements. The name of the legend placement // will be localized if desirable local is available List<EnumerationValue> loLegendPlacementList = ChartUtility.ConvertEnumForBinding(typeof(LegendPlacement), loChartMessages);
Now we should loop through these lists and add toolbar buttons.
// Loop through the list of the chart types
for (int i = 0; i < loChartTypeList.Count; i++)
{
EnumerationValue loChartType = loChartTypeList[i];
// Create tool strip menu item using localized name of the chart type
// and chart type image from the Manco.Chart assembly resources.
ToolStripMenuItem ltsmiChartType =
new ToolStripMenuItem(loChartType.DisplayText,
(Image)loCharResources.GetObject(loChartType.Value.ToString()),
new EventHandler(ChangeChartType));
// Store corresponding enumeration value in the menu item tag
// so it could be use to change chart type when menu item is clicked.
ltsmiChartType.Tag = loChartType.Value;
tsddbChartType.DropDownItems.Add(ltsmiChartType);
}
// Loop through the list of the legend placements
for (int i = 0; i < loLegendPlacementList.Count; i++)
{
EnumerationValue loLegendPlacement = loLegendPlacementList[i];
// Create tool strip menu item using localized name of the legend placement
// and chart type image from the Manco.Chart assembly resources.
ToolStripMenuItem ltsmiLegendPlacement =
new ToolStripMenuItem(loLegendPlacement.DisplayText,
(Image)loCharResources.GetObject("LegendPlacement_"
+ loLegendPlacement.Value.ToString()),
new EventHandler(ChangeLegendPlacement));
// Store corresponding enumeration value in the menu item tag
// so it could be use to change chart type when menu item is clicked.
ltsmiLegendPlacement.Tag = loLegendPlacement.Value;
tsddbLegendPlacement.DropDownItems.Add(ltsmiLegendPlacement);
}
The last thing we should to do - add event handlers for the tool strip menu items' OnClick event.
/// <summary>
/// Event handler for the chart type toolstrip buttons
/// </summary>
private void ChangeChartType(object sender, EventArgs e)
{
ToolStripMenuItem item = (ToolStripMenuItem)sender;
// Use chart API to change chart type
m_ChartControl.Charts[0].Layout.Type = (ChartType)item.Tag;
}
/// <summary>>
/// Event handler for the legend placement toolstrip buttons
/// </summary>
private void ChangeLegendPlacement(object sender, EventArgs e)
{
ToolStripMenuItem item = (ToolStripMenuItem)sender;
// Use chart API to change legend placement
m_ChartControl.Charts[0].Layout.Legend.Placement = (LegendPlacement)item.Tag;
}