Profile Picture

How to add OnDragEnd event to a moveable Legend of a Chart

Posted By joern kunze 6 Years Ago

How to add OnDragEnd event to a moveable Legend of a Chart

Author
Message
joern kunze
Problem Posted 6 Years Ago
View Quick Profile
Junior Member

Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)

Group: Forum Members
Last Active: 3 Months Ago
Posts: 86, Visits: 221
Hi Experts,
I have a moveable Legend (using NOffserTool based Controller-Tool) where I want to save Legend-Coordinates after the Legend has been moved so that I can restore Legend position when needed.
Moving the Legend works good - but I have some trouble getting the Legend position after it has been moved. The NOffsetTool offers only OnDoDrag but no EndDrag event:
https://www.nevron.com/forum/uploads/images/d6aaed4b-bc4e-42cd-9908-f5a7.jpg
 Within the OnDoDrag I can get the coordinates continously while the Legend is moved - but I would like to get the coordinates only when the Legend Drag has been finished. Is there a way to achieve this ?

Furthermore I wonder if there is an easy way to get the Legend Coordinates in the LegendMoveTool
LocationChanged event.

Present Situation:
     LegendMoveTool hLegendMoveTool = new LegendMoveTool();
      hLegendMoveTool.LocationChanged += eventSink_OnLegendEndDrag;
      _NevronChart.Controller.Tools.Add(hLegendMoveTool);

where
  public void eventSink_OnLegendEndDrag(object sender, EventArgs e) {
    Console.WriteLine("OnLegendEndDrag");
           // How can I get the Legend coordinates here - EventArgs e seems not to have them ?
   }

and
public class LegendMoveTool : Nevron.Chart.Windows.NOffsetTool
{
...
  public override void OnDoDrag(object sender, NMouseEventArgs e) {
         // event is fired continously when Legend is moved ....
           NPoint oPoint = e.Location;
      Console.WriteLine("OnDoDrag: X=" + oPoint.X + " / Y=" + oPoint.Y);   // Coordinates of the Legends lower right corner
      base.OnDoDrag(sender, e);
   }
}

Thanks for your help,
Best regards,
Joern




Nevron Support
Posted 6 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,000

Hi Joern,
You can override the OnEndDrag virtual method:
 class CustomOffsetTool : NOffsetTool
  {
   public override void OnEndDrag(object sender, NMouseEventArgs e)
   {
    base.OnEndDrag(sender, e);
   }
  }
Regarding the object which is currently being moved you can get the list of the currently selected panels using the GetSelectedDockPanels method of the tool but that is a protected member. Let us know if you meet any problems or have any questions.



Best Regards,
Nevron Support Team



joern kunze
Posted 6 Years Ago
View Quick Profile
Junior Member

Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)

Group: Forum Members
Last Active: 3 Months Ago
Posts: 86, Visits: 221
... overwriting OnEndDrag basically seems to work. But now 2 other problems arise:

1. Problem
When the entire form is resized or even maximized, the Legend automatically is moved to the upper right corner of the chart area (which is good). But in such a case, the OnEndDrag event is not fired. Is there a way to detect such an case with the LegendMoveTool (force somehow an OnEndDrag event)?

2. Setting the Legend position
When I use the OnEndDrag to determine Legend position;
     NPoint oPoint = ((NMouseEventArgs)eIn).Location;                               // Coordinates of the Legends lower right corner ?
      int iX = oPoint.X;
      int iY = oPoint.Y;
and use iX / iY afterwards to set the position:

NLegend oLegend = m_listCharts[i].Chart.DisplayOnLegend;
oLegend.Location = new NPointL(iX, iY);

the legend is not really at the position desired.

When I add an offset like 
     int iWidthLegend = (int)oLegend.MarginsArea.Width;
      int iHeightLegend = (int)oLegend.MarginsArea.Height;
     iX - = iWidthLegend;
      iY - = iHeightLegend;
The Legend is getting closer to the desired original point - but still quite far away.

So what must be done to bring the legend to exactly the position which was given by iX / iY from OnEndDrag ?

Furthermore, in case the given iX and iY are stored somewhere and to be restored later on a different screen, I want to ensure that the legend is always visible:
     NRectangleF oBoundsChart = m_listCharts[i].Chart.PlotArea;

      int iXMin = (int)oBoundsChart.X;
      int iXMax = iXMin + (int)oBoundsChart.Width;

      int iYMin = (int)oBoundsChart.Y ;
      int iYMax = iYMin  + (int)oBoundsChart.Height ;

and keep the legend position within this chart bounds area. But somehow here is also an considerable offset (actually the legend disappears without correcting  iY -= 100)

So how can I ensure, that the legend is always visible within the chart when the legend position is set manually ?


Thanks a lot for your help,
best regards,
Joern

Nevron Support
Posted 6 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,000

Hi Joern,

1. Problem
 When the entire form is resized or even maximized, the Legend automatically is moved to the upper right corner of the chart area (which is good). But in such a case, the OnEndDrag event is not fired. Is there a way to detect such an case with the LegendMoveTool (force somehow an OnEndDrag event)?
You can attach to the ContentAreaChanged event of the legend which if fired each time the content area changes (this is valid for app panels)

2. Setting the Legend position
 When I use the OnEndDrag to determine Legend position;
      NPoint oPoint = ((NMouseEventArgs)eIn).Location;                               // Coordinates of the Legends lower right corner ?
       int iX = oPoint.X;
       int iY = oPoint.Y;
 and use iX / iY afterwards to set the position:

NLegend oLegend = m_listCharts[i].Chart.DisplayOnLegend;
oLegend.Location = new NPointL(iX, iY);


 
When you set the location in this way it is actually specified in points – you need to ensure the location is specified in pixels in this case:
 
legend.Location = new NPointL(new NLength(x, NGraphicsUnit.Pixel), new NLength(y, NGraphicsUnit.Pixel));
 
Please elaborate on the last problem if it still persist after you change the location to use pixels instead of points.





Best Regards,
Nevron Support Team



joern kunze
Posted 6 Years Ago
View Quick Profile
Junior Member

Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)Junior Member (13 reputation)

Group: Forum Members
Last Active: 3 Months Ago
Posts: 86, Visits: 221
... thanks a lot, specifying PointL as Pixel does the trick :-)



Similar Topics


Reading This Topic