Right-click context menu customization


Author
Message
Santosh Chauhan
Santosh Chauhan
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)
Group: Forum Members
Posts: 4, Visits: 1

Hi,

 

I want to customize the right-click context menu for my Nevron chart control to get options like Chart Editor, Projections, Tools etc in the context menu. Could you please help me get that done. A code sample would be of great help.

 

I tried using the context menu present under toolbars of Nevron.Chart.WinForm.NChartCommandBarsManager; but it doesn’t work.

 

kind regards

Santosh


Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi Santosh,

You can easily display a context menu in response to mouse click event - the following code snippet shows how to show a dynamic context menu that contains two elements in case you click on a bar or the rest of the control:

  private void Form1_Load(object sender, EventArgs e)
  {
   NChart chart = nChartControl1.Charts[0];

   NBarSeries bar = new NBarSeries();

   bar.Values.Add(10);
   bar.Values.Add(20);
   bar.Values.Add(30);

   chart.Series.Add(bar);

   nChartControl1.MouseClick += new MouseEventHandler(nChartControl1_MouseClick);
  }

  void nChartControl1_MouseClick(object sender, MouseEventArgs e)
  {
   NHitTestResult hitTest = nChartControl1.HitTest(e.X, e.Y);
   ContextMenu menu = new ContextMenu();

   if (hitTest.ChartElement == ChartElement.DataPoint)
   {
    MenuItem barMenuItem = new MenuItem();
    barMenuItem.Click +=new EventHandler(barMenuItem_Click);
    barMenuItem.Tag = hitTest.DataPointIndex;
    barMenuItem.Text = "Toggle Fill";
    menu.MenuItems.Add(barMenuItem);
   }

   MenuItem editorMenuItem = new MenuItem();
   editorMenuItem.Click +=new EventHandler(editorMenuItem_Click);
   editorMenuItem.Text = "Show Editor...";
   menu.MenuItems.Add(editorMenuItem);

   menu.Show(nChartControl1, new Point(e.X, e.Y));
  }

  void editorMenuItem_Click(object sender, EventArgs e)
  {
   nChartControl1.ShowEditor();
  }

  void barMenuItem_Click(object sender, EventArgs e)
  {
   NChart chart = nChartControl1.Charts[0];
   NBarSeries bar = (NBarSeries)chart.Series[0];

   int barIndex = (int)((MenuItem)sender).Tag;

   if (bar.FillStyles[barIndex] == null)
   {
    bar.FillStyles[barIndex] = new NColorFillStyle(Color.Red);
   }
   else
   {
    bar.FillStyles[barIndex] = null;
   }

   nChartControl1.Refresh();
  }

Hope this helps - let us know if you meet any problems.



Best Regards,
Nevron Support Team


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search