Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1320
UltraChart Primitive HitTest
posted

Is there any way that I can determine through an X,Y coordinate if there is a primitive at that point?  Alternatively can anybody find an alternate solution to my problem?

My situation is that when the mouse is passed over a DataItem I am capturing a reference to that DataItem, and when the mouse is passed out I am releasing that reference.  E.g.

 

The problem is that if the DataItemOver event is never fired, but the mouse is moved away from the DataItem, then my reference is never released.  This can happen if a popup menu is displayed over the DataItem at which point the mouse is moved down that menu (and hence out of the DataItem).

What I would like to do is on the UltraChart.MouseClick event to test if the cursor is over a primitive so that, if it is not, then the reference can be released.  The UltraChart's HitTest method is no good for this purpose.

Any advice?  Thanks in advance.

  Private Sub ganttChart_DataItemOut(ByVal sender As Object, ByVal e As ChartDataEventArgs) Handles ganttChart.DataItemOut
    _CurrentPrimitive = Nothing
  End Sub
 
  Private Sub ganttChart_DataItemOver(ByVal sender As Object, ByVal e As ChartDataEventArgs) Handles ganttChart.DataItemOver
    _CurrentPrimitive = e.Primitive
  End Sub
 

Parents
No Data
Reply
  • 17605
    Verified Answer
    posted

    You can use WinChart interaction tools stuff for your case. Try using the following code:

        public partial class Form1 : Form

        {

            public Form1()

            {

                InitializeComponent();

            }

     

            private void Form1_Load(object sender, EventArgs e)

            {

                this.ultraChart1.ChartType = ChartType.GanttChart;

                this.ultraChart1.DataSource = DemoTable.Table(4);

                this.ultraChart1.DataBind();

     

                this.ultraChart1.Tooltips.Display = TooltipDisplay.Never;

     

                GanttTool ganttTool = new GanttTool(this.ultraChart1);

                this.ultraChart1.AddMouseMoveTool(ganttTool);

            }

     

            public class GanttTool : InteractionTool

            {

                private Box SelectedPrimitive { get; set; }

     

                public GanttTool(UltraChart chart)

                    : base(chart)

                {

     

                }

     

                public override bool CanStart()

                {

                    Primitive primitive = this.HitTest(this.LastInput.ViewPoint);

                    if (primitive == null)

                    {

                        return false;

                    }

     

                    Box box = primitive as Box;

                    if (box != null)

                    {

                        this.SelectedPrimitive = box;

                        return true;

                    }

     

                    return false;

                }

     

                public override void Start()

                {

                    // add your gantt item enter loging here

                }

     

                public override void MouseMove()

                {

                    base.MouseMove();

     

                    Primitive primitive = this.HitTest(this.LastInput.ViewPoint);

                    if (primitive != this.SelectedPrimitive)

                    {

                        StopTool();

                    }

                }

     

                public override void Stop()

                {

                    // add your gantt item out loging here

     

                    this.SelectedPrimitive = null;

                }

            }

        }

Children
No Data