10469 : Controlling resolution

Question

I want to lock the datescaler on a certain scale. I added the following code:

            Gantt1.DateScaler.ResizeType = ResizingType.StartLocked
            Gantt1.DateScaler.ReScaleWithControl = True

            Gantt1.DateScaler.StartTime = Date.Now
            Gantt1.DateScaler.StopTime = Gantt1.DateScaler.StartTime.AddDays(14)
            Gantt1.DateScaler.ZoomIntoResolution = NonLinearTime.TimeResolution.days

Now the datescaler will display two weeks, regardles of the width. I want to be able to set the scale of the datescaler (which I tried with the ZoomIntoResolution, but didn’t work out) and a startdate, just like M$ Project does.

In another answer, you suggested to implement the onDateScaleChangeEvent, to change the scale back to its original value. Can you be more specific? Maybe it’s part of the solution.

Answer

ZoomIntoResolution controls the lowest resolution available to the user.

The resolution is defined as VisibleTime/Space

You can also set the MinSpan property; this controls how much VisibleTime that must be on screen.

If you experiment with the scale and do something like this:
    private void dateScaler1_OnScaleChangeEvent(object sender, EventArgs e)
    {
      TimeSpan ts=(dateScaler1.StopTime.Subtract(dateScaler1.StartTime));
      double scale=(ts.Ticks /dateScaler1.Width);
      labelCurrentScale.Text = "Current scale: " + scale.ToString();
    }

You will find that you can produce a given resolution like this:
    private void buttonSetScaleToDays_Click(object sender, EventArgs e)
    {
      long scale = 20000000000;
      TimeSpan x=new TimeSpan(scale*dateScaler1.Width);
      dateScaler1.StopTime=dateScaler1.StartTime.Add(x);
     
    }

    private void buttonSetScaleToYears_Click(object sender, EventArgs e)
    {
      long scale = 1510000000000;
      TimeSpan x = new TimeSpan(scale * dateScaler1.Width);
      dateScaler1.StopTime = dateScaler1.StartTime.Add(x);

    }

Knowing this you can do the same calculations in the OnBeforeScaleOrSpanChange event and react to resolutions that you do not want and fix them by changing the e.NewStartTime and e.NewStopTime to valid values

Leave a Reply