/// <summary> /// Returns a value indicating whether the lightweight control is visible in the specified direction. /// </summary> /// <param name="visibleDirection">The direction in which to determine whether the lightweight control visible.</param> public bool IsVisible(VisibleDirection visibleDirection) { Control parent = Parent; if (parent != null && parent is LightweightControlContainerControl) return ((LightweightControlContainerControl)Parent).IsClientRectangleVisible(VirtualClientRectangleToParent(), visibleDirection); return false; }
/// <summary> /// Returns a value indicating whether the specified client rectangle is visible in the /// specified direction. /// </summary> /// <param name="rectangle">The client rectangle check the visibility of.</param> /// <param name="visibleDirection">The direction to check visibility.</param> public bool IsClientRectangleVisible(Rectangle rectangle, VisibleDirection visibleDirection) { // Obtain the client rectangle. Rectangle clientRectangle = ClientRectangle; // Adjust rectangle height if it's larger than the client height. if (rectangle.Height > clientRectangle.Height) rectangle.Height = clientRectangle.Height; // Adjust rectangle width if it's larger than the client width. if (rectangle.Width > clientRectangle.Width) rectangle.Width = clientRectangle.Width; // Check vertical visibility, as specified. bool verticallyVisible = rectangle.Y >= clientRectangle.Y && rectangle.Bottom <= clientRectangle.Bottom; bool horizontallyVisible = rectangle.X >= clientRectangle.X && rectangle.Right <= clientRectangle.Right; // Check visibility. if (visibleDirection == VisibleDirection.Vertical) return verticallyVisible; else if (visibleDirection == VisibleDirection.Horizontal) return horizontallyVisible; else if (visibleDirection == VisibleDirection.Both) return verticallyVisible && horizontallyVisible; else { // Can't happen unless a new type of VisibleDirection is added. Debug.Fail("Unexpected VisibleDirection."); return false; } }
/// <summary> /// Makes the lightweight control visible in the specified direction. /// </summary> /// <param name="visibleDirection">The direction in which to make the lightweight control visible.</param> public void MakeVisible(VisibleDirection visibleDirection) { Control parent = Parent; if (parent != null && parent is LightweightControlContainerControl) ((LightweightControlContainerControl)Parent).MakeClientRectangleVisible(VirtualClientRectangleToParent(), visibleDirection); }
/// <summary> /// Makes the specified client rectangle visible in the specified direction by adjusting /// the AutoScrollPosition as needed. /// </summary> /// <param name="rectangle">The client rectangle to make visible.</param> /// <param name="visibleDirection">The direction in which to make the client rectangle visible.</param> public void MakeClientRectangleVisible(Rectangle rectangle, VisibleDirection visibleDirection) { // Obtain the client rectangle. Rectangle clientRectangle = ClientRectangle; // Adjust rectangle height if it's larger than the client height. if (rectangle.Height > clientRectangle.Height) rectangle.Height = clientRectangle.Height; // Adjust rectangle width if it's larger than the client width. if (rectangle.Width > clientRectangle.Width) rectangle.Width = clientRectangle.Width; // Check vertical visibility, as specified. bool verticallyVisible = rectangle.Y >= clientRectangle.Y && rectangle.Bottom <= clientRectangle.Bottom; bool horizontallyVisible = rectangle.X >= clientRectangle.X && rectangle.Right <= clientRectangle.Right; // Check visibility. if (visibleDirection == VisibleDirection.Vertical) { if (verticallyVisible) return; } else if (visibleDirection == VisibleDirection.Horizontal) { if (horizontallyVisible) return; } else if (visibleDirection == VisibleDirection.Both) { if (verticallyVisible && horizontallyVisible) return; } // Calculate the vertical delta, as specified and needed. int verticalDelta = 0; if ((visibleDirection & VisibleDirection.Vertical) != 0 && !verticallyVisible) { if (rectangle.Top < 0) verticalDelta = rectangle.Top; else verticalDelta = rectangle.Bottom - clientRectangle.Height; } // Calculate the horizontal delta, as specified and needed. int horizontalDelta = 0; if ((visibleDirection & VisibleDirection.Horizontal) != 0 && !horizontallyVisible) { if (rectangle.Left < 0) horizontalDelta = rectangle.Left; else horizontalDelta = rectangle.Right - clientRectangle.Right; } // Adjust the auto-scroll position. AutoScrollPosition = new Point(Math.Abs(AutoScrollPosition.X) + horizontalDelta, Math.Abs(AutoScrollPosition.Y) + verticalDelta); }