Page 1 of 1
Colorband question
Posted: Mon Nov 10, 2008 4:53 pm
by 14045263
Hello,
I have a quick question about the colourband tool:
Is there a way of 'knowing' if a colourband start/end has moved?! The idea behind it is I would like to display the current start/end X location of the colourband as it's being dragged (it's just set to use the vertical axis).
Regards
Chris.
Posted: Mon Nov 10, 2008 5:04 pm
by narcis
Hi Chris,
You could use TChart's MouseMove event for that, for example:
Code: Select all
void tChart1_MouseMove(object sender, MouseEventArgs e)
{
if (colorBand1.Clicked(e.X, e.Y))
{
this.Text = colorBand1.Start.ToString() + ", " + colorBand1.End.ToString();
}
}
Posted: Tue Nov 11, 2008 12:08 pm
by 14045263
Hey Narcís, thanks for the reply.
Unfortunately it doesn't seem to work - when you 'click and hold' on either the Start or End of the region and then drag it somewhere, it doesn't seem to generate a mousemove event at all.
Can this be easily fixed do you know?
Regards
Chris
Posted: Wed Nov 12, 2008 11:26 am
by narcis
Hi Chris,
Sorry but I missed specific drag events for each ColorBandTool lines. You can do something like this:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private Line series;
private ColorBand tool;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Series.Add(series = new Line());
series.FillSampleValues();
tChart1.Tools.Add(tool = new ColorBand());
tool.Axis = tChart1.Axes.Bottom;
tool.Start = 2;
tool.End = 4;
tool.ResizeEnd = true;
tool.EndLine.DragLine += new EventHandler(EndLine_DragLine);
}
void EndLine_DragLine(object sender, EventArgs e)
{
tChart1.Header.Text = tool.End.ToString();
}
Posted: Wed Nov 12, 2008 12:12 pm
by 14045263
Good stuff - that's perfect.
Thanks for helping me on that one.
More on Dragging Color Bands
Posted: Wed Nov 12, 2008 2:09 pm
by 9644809
I have a color band that is attached to the bottom axis.
I cannot figure out how to control the cursor on the drag operation. It appears that the StartLine has some default behaviour, in that the cursor changes on hover over the Start line, but does not change on the EndLine hover or drag.
Target: WPF
This behaviour also appears in the TeeChart demo Drag Color band.
Posted: Wed Nov 12, 2008 2:58 pm
by narcis
Hi n8soft,
Yes, you are right. I think it's StartLine's cursor that doesn't change. I've added this to the defect list (TF02013567) to be fixed for next releases. A workaround could be doing something like this:
Code: Select all
void tChart1_MouseMove(object sender, MouseEventArgs e)
{
if (tool.Clicked(e.X, e.Y))
{
tChart1.Cursor = Cursors.VSplit;
}
else
{
tChart1.Cursor = Cursors.Default;
}
}
Posted: Mon Jan 05, 2009 12:18 pm
by 14045263
I think there may be a bug in the Clicked method when you have zoomed in.
Best way I can describe it is if I put 3 colourbands (all vertical) on chart, spaced fairly evenly, then zoom in on a portion of the chart which will not have a colourband in it, then click anywhere in the chart, the loop I have going (in mousedown) says that a colourband has been clicked.
Can you reproduce this at all?
Regards
Chris.
Posted: Mon Jan 05, 2009 12:36 pm
by narcis
Hi Chris,
Yes, I could reproduce the issue here using code below and added it to the list (TF02013677) to be investigated for next releases.
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private Steema.TeeChart.Tools.ColorBand colorBand1;
private Steema.TeeChart.Tools.ColorBand colorBand2;
private Steema.TeeChart.Tools.ColorBand colorBand3;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues(100);
colorBand1 = new Steema.TeeChart.Tools.ColorBand(tChart1.Chart);
colorBand1.Axis = tChart1.Axes.Bottom;
colorBand1.Start = 5;
colorBand1.End = 15;
colorBand2 = new Steema.TeeChart.Tools.ColorBand(tChart1.Chart);
colorBand2.Axis = tChart1.Axes.Bottom;
colorBand2.Start = 45;
colorBand2.End = 55;
colorBand3 = new Steema.TeeChart.Tools.ColorBand(tChart1.Chart);
colorBand3.Axis = tChart1.Axes.Bottom;
colorBand3.Start = 85;
colorBand3.End = 95;
tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
}
void tChart1_MouseMove(object sender, MouseEventArgs e)
{
tChart1.Cursor = colorBand1.Clicked(e.X, e.Y) ? Cursors.VSplit : Cursors.Default;
}
Posted: Mon Jan 05, 2009 12:47 pm
by 14045263
Thanks Narcís.
Posted: Mon Jan 05, 2009 4:59 pm
by 14045263
Infact, another question for you Narcís,
is it at all possible to get, from a region's DragStart (and DragEnd) events, the region that sent it? I noticed it's a colourline for the sender; if somehow I could fetch the region that the colourline is a part of I wouldn't have to worry too much about the bug above, you see.
Cheers,
Chris.
EDIT:
Don't worry, i've done it:
Code: Select all
FieldInfo[] fi = sender.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
Delegate endDragLineDelegate;
GraphRegion gr;
FieldInfo delegateField = (from theEvent in fi where ((FieldInfo)theEvent).Name == "EndDragLine" select theEvent).SingleOrDefault();
if (delegateField != null)
{
endDragLineDelegate = (Delegate)delegateField.GetValue(sender);
gr = endDragLineDelegate.Target as GraphRegion;
//gr will be the reference in this.Tools
}
Posted: Thu Feb 05, 2009 4:20 pm
by 14045263
yet another colorband question (I seem to be making heavy use of them...)
When you move the drag the sides of a [vertical] colourband, could you make it so it triggers a MouseMove event??
On an unrelated note, can I be the first person to ask for
GetNearestPoint to be public?!
Regards
Chris.
Posted: Fri Feb 06, 2009 10:11 am
by narcis
Hi Chris,
yet another colorband question (I seem to be making heavy use of them...)
No problem but would you mind starting a new thread for each new question? Otherwise threads go off the original topic and becomes difficult to follow them.
When you move the drag the sides of a [vertical] colourband, could you make it so it triggers a MouseMove event??
There's StartLine's and EndLine's DragLine event already. You could try enabling a boolean flag there which is checked in MouseMove event and its code only being executed if the flag is true.
On an unrelated note, can I be the first person to ask for GetNearestPoint to be public?!
Well, somehow it was asked in the thread you pointed
. Anyway, we made it public for the next release which will be published imminently.