Profile Picture

allow the control to move with panning

Posted By Enjoyear Guo 12 Years Ago
Author
Message
Enjoyear Guo
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 30, Visits: 1
I add a textbox control to the nChartControl1 as follows:
NTextBox textBox = new NTextBox();
textBox.Location = new Point(10,10);
textBox.Size = new Size(100,100);
nChartControl1.Controls.Add(textBox);
However, if I try to pan the chart left/right, the textbox control will always stays at the same place. Is it possible to allow it to move with panning.

Thank you.

Enjoyear


Nevron Support
Posted 12 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: Yesterday @ 8:46 AM
Posts: 3,054, Visits: 4,012

Hi,

We recommend you use an annotation attached to a data point for this case.



Best Regards,
Nevron Support Team



Enjoyear Guo
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 30, Visits: 1
Hi,
I am using the following way to solve my problem.

NScale2DToViewTransformation scaleToView =
new NScale2DToViewTransformation(nChartControl1.View.Context,
modelView.GetChartControl().Charts[0],
(int) StandardAxis.PrimaryX, (int) StandardAxis.PrimaryY);
NPointF point = new NPointF();
scaleToView.Transform(new NVector2DD(positionDataX, positionDataY), ref point);
TextBox.Location = new Point((int) point.X - TextBox.Size.Width/2, (int) point.Y + 5);




This could basically solve my problem when I call this method within the MouseMove event. But there is a small problem.
If the user is panning the chart too quickly(throw the chart left/right), then the position of the textbox could not updated when the mouse is released. Same problem will happen if the user zoomed into the chart. The textbox will still stay at the original place. I think the problem might be the nChartControl1.View.Context is not updated when I call the method above when the mouse is released.

So my question is:
Is there any event that will be raised if nChartControl1.View.Context is updated or the chart is shown?

Acutally, I found an event, which is nChartControl1.Paint. But I cannot figure out when this event is raised.
Thank you very much.

Enjoyear

Nevron Support
Posted 12 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: Yesterday @ 8:46 AM
Posts: 3,054, Visits: 4,012

Hi,

You can subscribe to a post callback on the chart (Chart Examples\Custom Painting) that is guaranteed to fire on every redraw and you can use it to update the text box position accordingly.



Best Regards,
Nevron Support Team



Enjoyear Guo
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 30, Visits: 1
Hi,

I've read that example. But I cannot find the class called NCustomPaintingBase that example inherits. It doesn't even exist in your documentation.

Actually, I find an interface which I though might work. It's called INPaintCallback. There are two methods in that interface, OnAfterPaint and OnBeforePaint. But I don't know when those events get fired.

Thank you.

Enjoyear

Nevron Support
Posted 12 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: Yesterday @ 8:46 AM
Posts: 3,054, Visits: 4,012

Hi Enjoyear,

The NCustomPaintingBase is part of the examples shipped with the control. In general you should create a class that implements the INPaintCallback interface and pass an instance of that class to the control. Afterwards the control will call the OnBeforePaint and OnAfterPaint methods during rendering before and after the panel content has been painted respectively. Let us know if you meet any problems.



Best Regards,
Nevron Support Team



Enjoyear Guo
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 30, Visits: 1
What does it mean pass an instance of the class to the control?

a) Pass it as argument of the constructor?!??!
b) Define it as a property!?!?!?
c) inherit from that class? (Can't do this because my class is already inheriting from usercontrol)
d) implement the interface (tried it and it doesn't work)

Please be more specific and I'd appreciate a quick code snippet if you could.

Thanks,
Enjoyear.


Nevron Support
Posted 12 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: Yesterday @ 8:46 AM
Posts: 3,054, Visits: 4,012

Hi,

The example shows very precisely how to install a custom paint callback. You can create your own class that implement ICustomPaintCallback and pass it to the chart:

class MyPaintCallback : INPaintCallback
{

        /// <summary>
        /// Occurs before the panel is painted.
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="eventArgs"></param>
        public virtual void OnBeforePaint(NPanel panel, NPanelPaintEventArgs eventArgs)
        {
        }

        /// <summary>
        /// Occurs after the panel is painted.
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="eventArgs"></param>
        public virtual void OnAfterPaint(NPanel panel, NPanelPaintEventArgs eventArgs)
        {

        }
}

somewhere in code:

nChartControl.Charts[0].PaintCallback = new MyPaintCallback();



Best Regards,
Nevron Support Team



Enjoyear Guo
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)Forum Member (30 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 30, Visits: 1
Hello experts,

Your method is working properly. Thank you very much for your code snippet.
Unfortunately it's still not solving my problem. I am afraid it might not be what I want.


Please see the attachment to better understand what I will talk about. I take a screen shot of those on the fly.

First of all, I add two textboxes to the nChartControl1. And Within the OnAfterPaint method, I update the position of all textboxes using the way I told you before.

_________ Copy those codes here ____________________

NScale2DToViewTransformation scaleToView =
new NScale2DToViewTransformation(nChartControl1.View.Context,
modelView.GetChartControl().Charts[0],
(int) StandardAxis.PrimaryX, (int) StandardAxis.PrimaryY);
NPointF point = new NPointF();
scaleToView.Transform(new NVector2DD(positionDataX, positionDataY), ref point);
TextBox.Location = new Point((int) point.X - TextBox.Size.Width/2, (int) point.Y + 5);
_____________________________________________________

But as long as the user is panning the chart only a little bit fast, what I will observe is that the chart stays at the same place, and only the position of the textboxes are updated. I guess I am not listening to the right event to update textbox positions.

Any idea how to solve this problem?
Many thanks!!

Best,
Enjoyear

Attachments
BeforePanning.png (90 views, 76.00 KB)
DuringPanning.png (90 views, 101.00 KB)
AfterPanning.png (80 views, 77.00 KB)


Similar Topics


Reading This Topic