CHart cursor and how to stop a drawline from drawing.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Snarkle
Newbie
Newbie
Posts: 91
Joined: Wed Jun 30, 2010 12:00 am

CHart cursor and how to stop a drawline from drawing.

Post by Snarkle » Tue Nov 09, 2010 5:18 am

Greetings,

I draw a number of drawlines on my chart .. generally used as trend lines.
There are 2 things I need to do when using them.

1. I want to change the Cursor to a cross when I'm drawing and have it return back to whatever it was before I started.
2. I want to be able to cancel a line study half way through its process.

1. I can change the cursor on the chart simply and change it back again just as easily .. once there is a drawline on the chart the cursor will never change back.
I tried playing about with the Drawlines .originalCursor property but it doesnt work consistently. How can I change my cursor to what I want for teh duration of the line drawing process and have it return back to the default? I thought it was a bug but I read in this forum its not ... so I dont understand the mechanism.

2. Drawlines happen in 2 parts .. first you create a line, then you drag across the chart to place the line.. I want to stop a drawing a line between the point that I have created the line .. BUT not yet dragged the mouse over the chart to actually draw .... basically if a user clicks the button to draw a line and 'starts' the process but then changes their mind and no longer wants a drawline and they hit escape I want to get the chart out of waiting for the line to be dragged.
--------------------
Cheers Phil.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CHart cursor and how to stop a drawline from drawing.

Post by Narcís » Tue Nov 09, 2010 11:20 am

Hi Phil,

1. You can use mouse events for that, for example:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        private Steema.TeeChart.Tools.DrawLine drawLine1;
        private Cursor originalCursor;

        private void InitializeChart()
        {
            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.FillSampleValues();

            drawLine1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);

            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
        }

        void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
            tChart1.Cursor = originalCursor;
        }

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            if (drawLine1.Active)
            {
                originalCursor = tChart1.Cursor;
                tChart1.Cursor = Cursors.WaitCursor;
            }
        }
2. I can not find a way to do that for now. I'll investigate a little bit further and if I can't find a solution I'll add your request to the wish-list to be considered for inclusion in future releases.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CHart cursor and how to stop a drawline from drawing.

Post by Narcís » Tue Nov 09, 2010 12:38 pm

Hi Phil,

We haven't found a way to cancel DrawLine's line drawing without modifying TeeChart sources so I have added your request (TF02015272) to the wish-list. In the meantime you have the option to let users finish drawing the line (wait for MouseUp event) and then if esc key has been hit you can delete it in MouseUp, for example:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        private Steema.TeeChart.Tools.DrawLine drawLine1;
        private Cursor originalCursor;
        private bool isLineDrawing;
        private bool deleteLine;

        private void InitializeChart()
        {
            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.FillSampleValues();

            drawLine1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
            isLineDrawing = false;

            tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
            tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
            tChart1.KeyDown += new KeyEventHandler(tChart1_KeyDown);
        }

        void tChart1_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Escape) && isLineDrawing)
            {
                isLineDrawing = false;
                deleteLine = true;
            }
        }

        void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
            if (deleteLine)
            {
                drawLine1.Lines.RemoveAt(drawLine1.Lines.Count - 1);
            }

            tChart1.Cursor = originalCursor;
            isLineDrawing = false;
        }

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            if (drawLine1.Active)
            {
                originalCursor = tChart1.Cursor;
                tChart1.Cursor = Cursors.Hand;
                isLineDrawing = true;
                deleteLine = false;
            }
        }
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Snarkle
Newbie
Newbie
Posts: 91
Joined: Wed Jun 30, 2010 12:00 am

Re: CHart cursor and how to stop a drawline from drawing.

Post by Snarkle » Wed Nov 10, 2010 6:06 am

ok thats cool ... if the user doesnt want to draw a trend line then they should not have clicked on that button anyway :-D

they can draw their line then select it and delete it ...

however ... I cannot change back my mouse cursor once a drawline has been drawn ..

I set the cursor to a cross when I mouse down (actually I start it from a context menu, no difference)
my mouse up fires and executes the code ... but the cross doesnt go away ...

this only seems to happen with drawlines ... I can change the cursor any other time .. but not after a drawline

I even added this

Code: Select all

            foreach (Tool tool in StockChart.Tools)
            {
                if (tool.GetType() == typeof(DrawLine))
                    ((DrawLine)tool).OriginalCursor = originalCursor;
            }
but that gives me a flashign cursor that flashes between an arrow and a cross
what IS ((DrawLine)tool).OriginalCursor for ???
--------------------
Cheers Phil.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CHart cursor and how to stop a drawline from drawing.

Post by Narcís » Wed Nov 10, 2010 10:21 am

Hi Phil,
I set the cursor to a cross when I mouse down (actually I start it from a context menu, no difference)
my mouse up fires and executes the code ... but the cross doesnt go away ...
It does in the code snippet I posted in my previous reply. Does this work fine at your end?
what IS ((DrawLine)tool).OriginalCursor for ???
OriginalCursor Gets or sets the Cursor to which the DrawLine defaults when the mouse is not over it.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Snarkle
Newbie
Newbie
Posts: 91
Joined: Wed Jun 30, 2010 12:00 am

Re: CHart cursor and how to stop a drawline from drawing.

Post by Snarkle » Wed Nov 10, 2010 10:45 pm

Hi Narcis,

I've attached a sandbox app (forgive all the extra non relevant junk in it )

Steps to replicate my problem.
cursor_woes.png
cursor_woes.png (11.93 KiB) Viewed 9650 times
Click Cross cursor and drag the mouse over the chart .. you'll see a cross
Click default cursor and drag the mouse over the chart .. the orignal cursor returns.

now ..

Click the cross, drag the cursor .. you'll see the cross
Click Pitchfork DrawlineItems and drag the pitchfork out .. you still have the cross
now click default cursor and voila you still have a cross.

My main app has the same behaviour even with one drawline ... I swear I'm not going mad and seeing things ... well no more than usual ...
Attachments
TChartSandbox2.zip
(51.8 KiB) Downloaded 376 times
--------------------
Cheers Phil.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CHart cursor and how to stop a drawline from drawing.

Post by Narcís » Thu Nov 11, 2010 2:56 pm

Hi Phil,

Thanks, I could reproduce the issue here and narrowed it down to the code snippet below. Actually it's not even necessary drawing a line, creating a DrawLine tool is enough. So I have added the issue to the defect list (TF02015276) to be fixed for future releases.

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();

            button1.Text = "Cross Cursor";
            button2.Text = "Default Cursor";
            button3.Text = "Create DrawLine tool";

            button1.Click += new EventHandler(button1_Click);
            button2.Click += new EventHandler(button2_Click);
            button3.Click += new EventHandler(button3_Click);
        }

        void button3_Click(object sender, EventArgs e)
        {
            tChart1.Tools.Add(new Steema.TeeChart.Tools.DrawLine());
        }

        void button2_Click(object sender, EventArgs e)
        {
            tChart1.Cursor = originalCursor;
        }

        void button1_Click(object sender, EventArgs e)
        {
            originalCursor = tChart1.Cursor;
            tChart1.Cursor = Cursors.Cross;
        }

        private Cursor originalCursor;

        private void InitializeChart()
        {
            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.FillSampleValues();
        }
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Snarkle
Newbie
Newbie
Posts: 91
Joined: Wed Jun 30, 2010 12:00 am

Re: CHart cursor and how to stop a drawline from drawing.

Post by Snarkle » Fri Nov 12, 2010 3:03 am

Is there a hack er .. I mean workaround :-) .. as I'm using the TChart source code ... something in Tools/DrawLines.cs perhaps ??
--------------------
Cheers Phil.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CHart cursor and how to stop a drawline from drawing.

Post by Narcís » Fri Nov 12, 2010 10:02 am

Hi Phil,

Je je. Investigating a little bit I found that in DrawLine.cs, at Steema.TeeChart.Tools.DrawLine.CheckCursor method, c is set to originalCursor which is Cursors.Cross. Having that in mind you can change this line in CheckCursor:

Code: Select all

          c = originalCursor;
For this:

Code: Select all

            c = (this.Chart.Parent != null) ? c = this.Chart.Parent.GetCursor() : originalCursor;
This works fine here for this particular case but I'm not sure this is the optimal solution so we will have to investigate the issue further.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Snarkle
Newbie
Newbie
Posts: 91
Joined: Wed Jun 30, 2010 12:00 am

Re: CHart cursor and how to stop a drawline from drawing.

Post by Snarkle » Tue Nov 16, 2010 2:01 am

"I'm not sure this is the optimal solution" ... Noted! ... I shall not hold you acountable if my modified code now steers aircraft from our skies or torments small furry animals ;-)

But other than that I'm enjoying wondreous changing "predictable" cursors ... Cheers
--------------------
Cheers Phil.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CHart cursor and how to stop a drawline from drawing.

Post by Narcís » Tue Nov 16, 2010 10:24 am

Hi Phil,

:lol: I meant that I found this interim fix worked but further investigation is necessary before including it in production code as I'm not sure if this should be changed at another location. Anyway, I'm glad to hear that worked fine for you.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CHart cursor and how to stop a drawline from drawing.

Post by Narcís » Thu Nov 25, 2010 10:38 am

Hi Phil,

After investigating the issue further we found that the best solution might be doing a small change in TeeChart.cs, Steema.TeeChart.TChart.OnMouseMove method where we have:

Code: Select all

        Cursor c = Cursor;
        chart.BroadcastMouseEvent(MouseEventKinds.Move, e, Control.ModifierKeys, ref c);
        chart.DoMouseMove(e.X, e.Y, ref c);
        Cursor.Current = c;
Changing:

Code: Select all

        Cursor.Current = c;
to:

Code: Select all

        Cursor = c;
Works fine for us. Could you please check if this also solves the issue at your end?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CHart cursor and how to stop a drawline from drawing.

Post by Narcís » Thu Nov 25, 2010 3:13 pm

Hi Phil,

Please ignore my last post. We found that solution damaged other tools that also change cursors. We will continue searching for the optimal solution.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: CHart cursor and how to stop a drawline from drawing.

Post by Narcís » Fri Nov 26, 2010 4:20 pm

Hi Phil,

We have finally found a solution that seems to work on all circumstances. We will include this for next maintenance release due out very soon. For changing the cursor in a chart when there's a DrawLine tool present you'll have to change DrawLine's OriginalCursor property, for example:

Code: Select all

        void button2_Click(object sender, EventArgs e)
        {
            tChart1.Cursor = originalCursor;

            if (tChart1.Tools.Count > 0)
            {
              (tChart1.Tools[0] as Steema.TeeChart.Tools.DrawLine).OriginalCursor = tChart1.Cursor;
            }
        }
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply