Page 1 of 1

Hit CursorTool with ContextMenuStrip

Posted: Wed Jan 16, 2008 7:33 am
by 9092018
Good morning!

I am showing a ContextMenuStrip on my chart when pressing the right mousebutton. What I want now is, that there shows up an additional MenuItem if the mouspointer is located over a CursorTool while opening the ContextMenuStrip.

Code: Select all

                for (int i = 0; (i < isgChart1.mCursorCounter) && (hitScooter == -1); i++)
                    if (((Steema.TeeChart.Tools.CursorTool)isgChart1.mCursorCollection[i]).Clicked(contextMenuStrip1.Left, contextMenuStrip1.Top) != Steema.TeeChart.Tools.CursorClicked.None)
                    {
                        hitScooter = i;
                    }
                }

                deleteScooterToolStripMenuItem.Visible = (hitScooter != -1);
            }
That works fine if the chart is the only component in the application but if not, the location of the ContextMenuStrip does not correspond to the position of the CursorTool as the CursorTool seems to be located relatively to the upper left corner of the chart but the ContextMenuStrip is located relatively to the upper left corner of the application window.

I tried to determine the real position of the CursorTool by the following code:

Code: Select all

                int xPos=0;
                int yPos=0;

                for (int i = 0; (i < isgChart1.mCursorCounter) && (hitScooter == -1); i++)
                {
                    for (int x = 0; x < 1300; x += 2)
                    {
                        for (int y = 0; y < 1100; y += 50)
                        {
                            if ((isgChart1.mCursorCollection[i] != null) && (((Steema.TeeChart.Tools.CursorTool)isgChart1.mCursorCollection[i]).Clicked(x, y) != Steema.TeeChart.Tools.CursorClicked.None))
                            {
                                xPos=x;
                                yPos=y;
                            }
                        }
                    }
                }
The difference between xPos and contextMenuStrip1.Left seems to be the width of components located left to the chart.

To cut a long story short: How can I come to the desired result?

best wishes,

Rf.

Posted: Wed Jan 16, 2008 8:32 am
by 9092018
Hello again!

I found a solution on my own :)

Code: Select all

            Point menuLocation = isgChart1.PointToClient(new Point(contextMenuStrip1.Left, contextMenuStrip1.Top));

                for (int i = 0; (i < isgChart1.mCursorCounter) && (hitScooter==-1); i++)
                {
                    if (((Steema.TeeChart.Tools.CursorTool)isgChart1.mCursorCollection[i]).Clicked(menuLocation.X, menuLocation.Y) != Steema.TeeChart.Tools.CursorClicked.None)
                    {
                        hitScooter = i;
                    }
                }

                if (hitScooter!=-1)
                {
                    isgChart1.deleteCursorTool(hitScooter);
                }
best wishes,
Rf.