ColorBand Tool dragging

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Sean
Newbie
Newbie
Posts: 2
Joined: Fri Aug 18, 2023 12:00 am

ColorBand Tool dragging

Post by Sean » Wed Aug 23, 2023 4:02 pm

Hi,
I have a chart with a ColorBand tool active on the Bottom Axis. What I'm trying to do is drag the entire ColorBand like you can when using the ScrollPager Tool but I can't find any example of doing this.

I'm already dragging the StartLine and EndLine using the DragLine events for each but also want to move the entire ColorBand when the left mouse is down and moving on the ColorBand.

Kind regards,
Sean

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: ColorBand Tool dragging

Post by Marc » Thu Aug 24, 2023 10:07 am

Hello Sean,

This code will do it:

Code: Select all

//disable zoom somewhere in your code:
tChart1.Zoom.Direction = ZoomDirections.None;

...... // ..........

//declare
bool mouseDown = false;
Point startPoint;
double startValue;

private void tChart1_MouseDown(object sender, MouseEventArgs e)
{
    //check the mousedown is in the band area
    if ((tChart1.Axes.Bottom.CalcPosPoint(e.X) > colorBand1.Start) 
                && (tChart1.Axes.Bottom.CalcPosPoint(e.X) < colorBand1.End))
    {
        mouseDown = true;
        startPoint = new Point(e.X, e.Y);
        startValue = colorBand1.Start;
    }
}

private void tChart1_MouseMove(object sender, MouseEventArgs e)
{
    if (mouseDown)
    {
        //assume horiz axis displacement for this example
        double displacementX = tChart1.Axes.Bottom.CalcPosPoint(e.X) - tChart1.Axes.Bottom.CalcPosPoint(startPoint.X);

        double colorBandWidth = colorBand1.End - colorBand1.Start;
        colorBand1.Start = startValue + (displacementX);
        colorBand1.End = colorBand1.Start + colorBandWidth;
    }
}

private void tChart1_MouseUp(object sender, MouseEventArgs e)
{
    mouseDown = false;
}
Regards,
Marc Meumann
Steema Support

Post Reply