Index

Subject: Re: Drawing a vertical grid while mouse over chart
From: rposeika@cbautomation.com (Newsgroups)  Steema Software SL
Newsgroup: steema.public.teechartfornet.lite  
Date: Tue, 08 Mar 2005 22:25:32 +0100

From other websites - the key was not to use the tChart.Canvas.

Part of System.Drawing is;
ControlPaint.DrawReversibleLine(p1, p2, Color.Transparent);

Solution code snippet

private void tChart1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Point p1 = new Point();
Point p2 = new Point();
Rectangle r1 = new Rectangle();

r1 = tChart1.Chart.ChartRect;
p1.X = e.X; p1.Y = e.Y;
if (r1.Contains(p1) == true)
{

p1 = oldP1; p2 = oldP2;

if (p1.X == -1)
{
tChart1.Refresh();
}
else
{
ControlPaint.DrawReversibleLine(p1, p2, Color.Transparent);
}
Point newPt = PointToScreen(new Point(e.X, e.Y));
p1.X = newPt.X;
newPt = PointToScreen(new Point(p1.X, r1.Top));
p1.Y = newPt.Y;

p2.X = p1.X;
newPt = PointToScreen(new Point (p2.X, r1.Top + r1.Height));

p2.Y = newPt.Y;
ControlPaint.DrawReversibleLine(p1, p2, Color.Transparent);
//a little extra
int clicked = fastLine1.Clicked(e.X,e.Y);
if(clicked != -1)
{
double myD;
myD = fastLine1.XValues[clicked];
DateTime myDT;
myDT = DateTime.FromOADate(myD);
lblDT.Text = myDT.ToString("MM/dd/yy hh:mm:ss");
lblVAL.Text = fastLine1.YValues[clicked].ToString();
}
oldP1 = p1;
oldP2 = p2;
}
}

private void tChart1_MouseLeave(object sender, System.EventArgs e)
{
oldP1.X = -1;
tChart1.Refresh();
}

Regards

Rudy wrote:

> In the win32 TChart there was some code example I used to get
> the mouse movement and draw a vertical line across the chart.

> I have started this in the dotNet Tchart - but some properties / methods
> in the framework are not the same / I have not discovered them.

> I have the vertical line as I want, but I am not painting out the old
> vertical line.

> See code snippet and thanks in advance.
> Old Win32 code and a Pen Mode I -
> with Chart1,Canvas do
> begin
> Pen.Color := CrossHairColor;
> Pen.Style := CrossHairStyle;
> Pen.Mode := pmXor;
> Pen.Width := 1;
> MoveTo(ax, ChartRect.Top-Height3D);
> LineTo(ax, ChartRect.Bottom-Height3D);
> end;


> private void tChart1_MouseMove(object sender,
> System.Windows.Forms.MouseEventArgs e)
> {
> Point p1 = new Point();
> Point p2 = new Point();
> Rectangle r1 = new Rectangle();

> r1 = tChart1.Chart.ChartRect;
> p1.X = e.X; p1.Y = e.Y;
> if (r1.Contains(p1) == true)
> {

> p1 = oldP1; p2 = oldP2;
> tChart1.Canvas.Pen.Width = 1;
> tChart1.Canvas.Pen.Transparency = 0;

> tChart1.Canvas.Pen.Color = Color.AntiqueWhite;
> tChart1.Canvas.Line(p1, p2);

> tChart1.Canvas.Pen.Visible = true;
> p1.X = e.X; p1.Y = r1.Top;
> p2.X = e.X; p2.Y = r1.Top + r1.Height;

> tChart1.Canvas.Pen.Color = Color.ForestGreen;
> tChart1.Canvas.Pen.Width = 1;
> tChart1.Canvas.Line(p1, p2);

> oldP1 = p1;
> oldP2 = p2;
> }
> }