Selecting Lines
Posted: Thu Oct 06, 2011 3:40 am
Is it possible to select multiple lines with the mouse, drawn with the line tool?
Steema Software - Customer Support Forums
http://216.92.101.67/support/
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private Steema.TeeChart.Styles.FastLine series1, series2,series3;
int HandleSize = 5;
Color oldBrushColor;
Color oldPenColor;
bool oldGradient;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
series1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
series2 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
series3 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
series1.FillSampleValues();
series2.FillSampleValues();
series3.FillSampleValues();
series1.Color= Color.Blue;
series2.Color = Color.Orange;
series3.Color = Color.Red;
tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
}
void tChart1_MouseDown(object sender, MouseEventArgs e)
{
Steema.TeeChart.ChartClickedPart p;
Point pp = new Point();
if (tChart1.Series.Count != 0)
{
foreach (Steema.TeeChart.Styles.Series s in tChart1.Series)
{
if (s.Clicked(e.X, e.Y) != -1 && ModifierKeys == Keys.Control)
{
tChart1.AutoRepaint = false;
pp.X = e.X;
pp.Y = e.Y;
tChart1.Chart.CalcClickedPart(pp, out p);
if (p.Part == Steema.TeeChart.ChartClickedPartStyle.Series)
{
DrawSelection(p);
}
}
else
{
tChart1.AutoRepaint = true;
}
}
}
}
private void DrawSelection(Steema.TeeChart.ChartClickedPart Part)
{
int t, X, Y;
int tmpStep, tmpLast, tmpCount;
Steema.TeeChart.Styles.Series tmpSeries = Part.ASeries;
Steema.TeeChart.Drawing.Graphics3D g = tChart1.Chart.Graphics3D;
if (Part.ASeries != null)
{
tmpCount = tmpSeries.LastVisibleIndex - tmpSeries.FirstVisibleIndex;
if (tmpCount == 0) tmpCount = Part.ASeries.Count;
if (tmpCount > 20)
{
tmpStep = tmpCount/ 20;
}
else
{
tmpStep = 1;
}
t = tmpSeries.FirstVisibleIndex;
if (t == -1)t = 0;
tmpLast = tmpSeries.LastVisibleIndex;
if (tmpLast == -1) tmpLast = Part.ASeries.Count - 1;
oldBrushColor = g.Brush.Color;
oldPenColor = g.Pen.Color;
oldGradient = g.Gradient.Visible;
g.Gradient.Visible = false;
g.Brush.Color = Color.Black;
g.Pen.Color = Color.Black;
while (t < tmpLast)
{
X = tmpSeries.CalcXPos(t);
Y = tmpSeries.CalcYPos(t);
g.Rectangle(RectFormPoint1(X, Y), tmpSeries.MiddleZ);
t += tmpStep;
}
g.Brush.Color = oldBrushColor;
oldPenColor = g.Pen.Color = oldBrushColor;
g.Gradient.Visible = oldGradient;
series1.Color = Color.Blue;
series2.Color = Color.Orange;
series3.Color = Color.Red;
}
}
private Rectangle RectFormPoint1(int X, int Y)
{
//return a rectangle few pixels around XY point }
return Steema.TeeChart.Utils.FromLTRB(X - HandleSize, Y - HandleSize, X + HandleSize, Y + HandleSize);
}