Profile Picture

Right-click context menu customization

Posted By Santosh Chauhan 13 Years Ago
Author
Message
Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

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



Santosh Chauhan
Posted 13 Years Ago
View Quick Profile
Forum Newbie

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
Last Active: 13 Years Ago
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





Similar Topics


Reading This Topic