private void OnSlideTimerTick(object sender, EventArgs e)
{
// Check to see if we allowed to perform operations
if (Disposing || IsDisposed)
{
// Make sure the timer is disposed of correctly
if (_slideTimer != null)
{
_slideTimer.Stop();
_slideTimer.Dispose();
_slideTimer = null;
}
return;
}
// Action to take depends on current state
switch (_state)
{
case DockingAutoHiddenShowState.Hidden:
case DockingAutoHiddenShowState.Showing:
// No need for timer as sliding has finished
_slideTimer.Stop();
break;
case DockingAutoHiddenShowState.SlidingOut:
{
bool finished = true;
Size newSlideSize = Size;
Point newSlideLocation = Location;
Point newInnerLocation = _inner.Location;
// Find the new size and location when sliding out from the edge
switch (_edge)
{
case DockingEdge.Left:
newSlideSize.Width = Math.Min(newSlideSize.Width + SLIDE_DISTANCE, _endRect.Width);
newInnerLocation.X = newSlideSize.Width - _inner.Width;
finished = (newSlideSize.Width == _endRect.Width);
break;
case DockingEdge.Right:
newSlideSize.Width = Math.Min(newSlideSize.Width + SLIDE_DISTANCE, _endRect.Width);
newSlideLocation.X = Math.Max(newSlideLocation.X - SLIDE_DISTANCE, _endRect.X);
finished = (newSlideSize.Width == _endRect.Width);
break;
case DockingEdge.Top:
newSlideSize.Height = Math.Min(newSlideSize.Height + SLIDE_DISTANCE, _endRect.Height);
newInnerLocation.Y = newSlideSize.Height - _inner.Height;
finished = (newSlideSize.Height == _endRect.Height);
break;
case DockingEdge.Bottom:
newSlideSize.Height = Math.Min(newSlideSize.Height + SLIDE_DISTANCE, _endRect.Height);
newSlideLocation.Y = Math.Max(newSlideLocation.Y - SLIDE_DISTANCE, _endRect.Y);
finished = (newSlideSize.Height == _endRect.Height);
break;
}
// Update position to reflect the change
_inner.SetBounds(newInnerLocation.X, newInnerLocation.Y, _endRect.Width, _endRect.Height);
SetBounds(newSlideLocation.X, newSlideLocation.Y, newSlideSize.Width, newSlideSize.Height);
if (finished)
{
// When finished we no longer need the timer and enter the showing state
_state = DockingAutoHiddenShowState.Showing;
AutoHiddenShowingStateEventArgs args = new AutoHiddenShowingStateEventArgs(_page, _state);
OnAutoHiddenShowingStateChanged(args);
_slideTimer.Stop();
}
}
break;
case DockingAutoHiddenShowState.SlidingIn:
{
bool finished = true;
Size newSlideSize = Size;
Point newSlideLocation = Location;
Point newInnerLocation = _inner.Location;
// Find the new size and location when sliding inwards to the edge
switch (_edge)
{
case DockingEdge.Left:
newSlideSize.Width = Math.Max(newSlideSize.Width - SLIDE_DISTANCE, 0);
newInnerLocation.X = newSlideSize.Width - _inner.Width;
finished = (newSlideSize.Width == _startRect.Width);
break;
case DockingEdge.Right:
newSlideSize.Width = Math.Max(newSlideSize.Width - SLIDE_DISTANCE, 0);
newSlideLocation.X = Math.Min(newSlideLocation.X + SLIDE_DISTANCE, _startRect.X);
finished = (newSlideSize.Width == _startRect.Width);
break;
case DockingEdge.Top:
newSlideSize.Height = Math.Max(newSlideSize.Height - SLIDE_DISTANCE, 0);
newInnerLocation.Y = newSlideSize.Height - _inner.Height;
finished = (newSlideSize.Height == _startRect.Height);
break;
case DockingEdge.Bottom:
newSlideSize.Height = Math.Max(newSlideSize.Height - SLIDE_DISTANCE, 0);
newSlideLocation.Y = Math.Min(newSlideLocation.Y + SLIDE_DISTANCE, _startRect.Y);
finished = (newSlideSize.Height == _startRect.Height);
break;
}
// Update position to reflect the change
_inner.SetBounds(newInnerLocation.X, newInnerLocation.Y, _endRect.Width, _endRect.Height);
SetBounds(newSlideLocation.X, newSlideLocation.Y, newSlideSize.Width, newSlideSize.Height);
if (finished)
MakeHidden();
}
break;
}
}