Hi
I have my own set of classes that persist my chart so I can recreate it later. For the drawline tool, I save the properties of each line in the .Lines collection (StartPos, EndPos, and Pen information).
When I reload a chart, I add a drawline tool and then manually add drawlineitems. The lines are drawn back on the chart but if I mouse over I get an error; 'Object reference not set to an instance of an object'?
How do I programatically add lines to a drawline tool?
ANSWER: When creating the drawlineitem I need to pass the drawline to it's constructor; ie. line = New Steema.TeeChart.Tools.DrawLineItem(dl) where dl is the drawline tool.
Something else though. Is it possible to add/access the event handlers of a drawlineitem. I want to know when the user clicks on a drawlineitem?
Programmatic Drawlines
Re: Programmatic Drawlines
HHello rossmc,
I made a simple project that I think you can use for your application. Please see next code works correctly in your application:
If your problem still appears, please you could send us a simple project because we can reproduce the problem here and we try to solve it.
I hope will help.
Thanks,
I made a simple project that I think you can use for your application. Please see next code works correctly in your application:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
Steema.TeeChart.Styles.Line line1;
Steema.TeeChart.Tools.DrawLine drawLine1;
Steema.TeeChart.Tools.DrawLineItem I;
private void InitializeChart()
{
line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues();
drawLine1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
drawLine1.Pen.Color = Color.Blue;
drawLine1.Pen.Width = 2;
I=new Steema.TeeChart.Tools.DrawLineItem(drawLine1);
double tmp = line1.YValues.Range / 5.0;
I.StartPos = new Steema.TeeChart.Drawing.PointDouble(5, line1.YValues.Maximum - tmp);
I.EndPos = new Steema.TeeChart.Drawing.PointDouble(15, line1.YValues.Minimum + tmp);
drawLine1.EnableDraw = false;
drawLine1.DragLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawLine1_DragLine);
}
void drawLine1_DragLine(Steema.TeeChart.Tools.DrawLine sender)
{
I=drawLine1.Selected;
tChart1.Header.Text = "Start: (x: "+ I.StartPos.X.ToString("0.00")+ ", y: " + I.StartPos.Y.ToString("0.00")+")";
tChart1.SubHeader.Visible = true;
tChart1.SubHeader.Text = "End: (x: " + I.EndPos.X.ToString("0.00") + ", y: " + I.EndPos.Y.ToString("0.00") + ")";
}
I hope will help.
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Programmatic Drawlines
Thanks for that code, it's very helpful. Is there a way I can trap a right mouse button click on a drawlineitem now? No events fire (that I can see) when I right click a drawlineitem?
Re: Programmatic Drawlines
Hello rossmc,
You have to options:
First: You could change button with the drawline dragging to right use next code.
Second: If you want drawline tool dragging both left and right, I recommend use MouseDown event or MouseClick event as next code. Please check next code works correctly in your application.
I hope will helps.
Thanks,
You have to options:
First: You could change button with the drawline dragging to right use next code.
Code: Select all
drawLine1.Button = System.Windows.Forms.MouseButtons.Right;
Code: Select all
void tChart1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
drawLine1.Button = System.Windows.Forms.MouseButtons.Right;
Steema.TeeChart.Tools.DrawLineItem I1 = drawLine1.Selected;
tChart1.Header.Text = "Start: (x: " + I.StartPos.X.ToString("0.00") + ", y: " + I.StartPos.Y.ToString("0.00") + ")";
tChart1.SubHeader.Visible = true;
tChart1.SubHeader.Text = "End: (x: " + I.EndPos.X.ToString("0.00") + ", y: " + I.EndPos.Y.ToString("0.00") + ")";
}
else { drawLine1.Button = System.Windows.Forms.MouseButtons.Left; }
}
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Programmatic Drawlines
I suppose I should have been more specific. What I really want is:
Left click on drawline selects the line (as per normal operation)
Right-click on drawline shows a drawline specific context-sensitive menu.
So really what I am looking for is a way to trap a right-click on a drawline.
Left click on drawline selects the line (as per normal operation)
Right-click on drawline shows a drawline specific context-sensitive menu.
So really what I am looking for is a way to trap a right-click on a drawline.
Re: Programmatic Drawlines
Hello rossmc,
If you want to click the line using button right, you should only be use MouseDown Event, or MouseDown and MouseClick event. I recommend use a similar code as next:
I hope will helps.
Thanks,
If you want to click the line using button right, you should only be use MouseDown Event, or MouseDown and MouseClick event. I recommend use a similar code as next:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
Steema.TeeChart.Styles.Line line1;
Steema.TeeChart.Tools.DrawLine drawLine1;
Steema.TeeChart.Tools.DrawLineItem I;
private void InitializeChart()
{
line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues();
drawLine1 = new Steema.TeeChart.Tools.DrawLine(tChart1.Chart);
drawLine1.Pen.Color = Color.Blue;
drawLine1.Pen.Width = 2;
I=new Steema.TeeChart.Tools.DrawLineItem(drawLine1);
double tmp = line1.YValues.Range / 5.0;
I.StartPos = new Steema.TeeChart.Drawing.PointDouble(5, line1.YValues.Maximum - tmp);
I.EndPos = new Steema.TeeChart.Drawing.PointDouble(15, line1.YValues.Minimum + tmp);
drawLine1.EnableDraw = false;
drawLine1.DragLine += new Steema.TeeChart.Tools.DrawLineEventHandler(drawLine1_DragLine);
tChart1.AllowScroll += new Steema.TeeChart.TChart.AllowScrollEventHandler(tChart1_AllowScroll);
tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
}
void tChart1_AllowScroll(Steema.TeeChart.Axis a, Steema.TeeChart.TChart.AllowScrollEventArgs e)
{
e.AllowScroll = false;
}
void tChart1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Text = "End: (x: " + I.EndPos.X.ToString("0.00") + ", y: " + I.EndPos.Y.ToString("0.00") + ")";
}
}
void drawLine1_DragLine(Steema.TeeChart.Tools.DrawLine sender)
{
I = drawLine1.Selected;
tChart1.Header.Text = "Start: (x: " + I.StartPos.X.ToString("0.00") + ", y: " + I.StartPos.Y.ToString("0.00") + ")";
tChart1.SubHeader.Visible = true;
tChart1.SubHeader.Text = "End: (x: " + I.EndPos.X.ToString("0.00") + ", y: " + I.EndPos.Y.ToString("0.00") + ")";
}
}
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |