Modifying the Default Context Menu
The default RadChartView context menu can be customized in the ContextMenuOpening event handler.
New Menu Item
In order to add custom menu items to the default context menu, you should create menu item instances in the ContextMenuOpening event handler and add them to the e.ContextMenu.Items collection. The following example adds an item responsible for exporting the chart to an image.
Subscribe to Event
this.radChartView1.ContextMenuOpening += radChartView1_ContextMenuOpening;
AddHandler RadChartView1.ContextMenuOpening, AddressOf RadChartView1_ContextMenuOpening
Handle Event
private void radChartView1_ContextMenuOpening(object sender, ChartViewContextMenuOpeningEventArgs e)
{
RadMenuItem customMenuItem = new RadMenuItem();
customMenuItem.Text = "Export Chart";
customMenuItem.Click += customMenuItem_Click;
RadMenuSeparatorItem separator = new RadMenuSeparatorItem();
e.ContextMenu.Items.Add(separator);
e.ContextMenu.Items.Add(customMenuItem);
}
private void customMenuItem_Click(object sender, EventArgs e)
{
string filePath = @"..\..\..\exportedChart.png";
this.radChartView1.ExportToImage(filePath, this.radChartView1.Size, System.Drawing.Imaging.ImageFormat.Png);
}
Private Sub RadChartView1_ContextMenuOpening(sender As Object, e As ChartViewContextMenuOpeningEventArgs)
Dim customMenuItem As New RadMenuItem()
customMenuItem.Text = "Export Chart"
AddHandler customMenuItem.Click, AddressOf CustomMenuItem_Click
Dim separator As New RadMenuSeparatorItem()
e.ContextMenu.Items.Add(separator)
e.ContextMenu.Items.Add(customMenuItem)
End Sub
Private Sub CustomMenuItem_Click(sender As Object, e As EventArgs)
Dim filePath As String = "..\..\..\exportedChart.png"
Me.RadChartView1.ExportToImage(filePath, Me.RadChartView1.Size, System.Drawing.Imaging.ImageFormat.Png)
End Sub