Profile Picture

Menu activated with a right click

Posted By Ben Alexander 14 Years Ago
Author
Message
Nevron Support
Posted 14 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 Ben,

There is no embedded context menu functionality, but you can easily add one - the following example shows how to display a simple context menu when the user clicks on points in the chart:

  struct DataItemTag
  {
   public DataItemTag(NSeriesBase series, int index)
   {
    Series = series;
    Index = index;
   }

   public NSeriesBase Series;
   public int Index;
  }

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

   // sample data
   double[] pointYValues = new double[] { 10, 20, 30 };
   double[] pointXValues = new double[] { 10, 20, 30 };

   NPointSeries point = new NPointSeries();
   point.UseXValues = true;
   chart.Series.Add(point);

   for (int i = 0; i < pointYValues.Length; i++)
   {
    point.Values.Add(pointYValues[i]);
    point.XValues.Add(pointXValues[i]);
   }

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

  void nChartControl1_MouseClick(object sender, MouseEventArgs e)
  {
   NHitTestResult result = nChartControl1.HitTest(e.X, e.Y);

   if (result.ChartElement == ChartElement.DataPoint)
   {
    ContextMenu menu = new ContextMenu();

    DataItemTag tag = new DataItemTag(result.Series, result.DataPointIndex);

    MenuItem option1 = new MenuItem("Make Red");
    option1.Click +=new EventHandler(option1_Click);
    option1.Tag = tag;
    menu.MenuItems.Add(option1);

    MenuItem option2 = new MenuItem("Reset To Default");
    option2.Click += new EventHandler(option2_Click);
    option2.Tag = tag;
    menu.MenuItems.Add(option2);

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

  void option1_Click(object sender, EventArgs e)
  {
   MenuItem item = (MenuItem)sender;
   DataItemTag tag = (DataItemTag)item.Tag;

   ((NPointSeries)tag.Series).FillStyles[tag.Index] = new NColorFillStyle(Color.Red);
   nChartControl1.Refresh();
  }

  void option2_Click(object sender, EventArgs e)
  {
   MenuItem item = (MenuItem)sender;
   DataItemTag tag = (DataItemTag)item.Tag;

   ((NPointSeries)tag.Series).FillStyles.Remove(tag.Index);
   nChartControl1.Refresh();
  }

of course this sample can be extended further. Let us know if you have any questions or meet any problems.



Best Regards,
Nevron Support Team



Ben Alexander
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 5, Visits: 1
In my application I provide most of the user interface through code written in C#, and then I have largish windows where users see their Nevron-driven graphics. There are some options (such as legend position and choice of mouse interactivity tool) where I'd like to give users immediate access to some of their most frequently selected options by providing a menu activated with a right mouse click (perhaps with a couple of pull-aside menus hanging off of that main menu). Is there an easy way to implement such a menu within Nevron Chart? I know that I can capture the right-click event in Chart, but am I then going to have to draw the menu, track the user's mouse position, highlight/un-highlight menu items as the mouse passes over them, capture clicks, and do all that sort of stuff myself, or has that functionality already been built into Nevron Chart? I know that it may seem like only a small advantage, but I think that sometimes a right-click menu can be MUCH handier for users than the multi-step process of starting a dialog box, selecting your desired options, and then pressing an OK button. So, does anybody know of any easy way to make and manage menu's such as the one I've described here, or is this capability not a standard part of the Nevron Chart ?

Thanks,
Ben



Similar Topics


Reading This Topic