Example #1
0
        /// <summary>
        /// Perform a layout of the elements.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override void Layout(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Validate incoming reference
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // During disposal the view control will not longer exist
            if (_viewControl != null)
            {
                // Ensure context has the correct control
                using (CorrectContextControl ccc = new CorrectContextControl(context, _viewControl))
                {
                    // We take on all the available display area
                    ClientRectangle = context.DisplayRectangle;

                    // Are we allowed to layout child controls?
                    if (!context.ViewManager.DoNotLayoutControls)
                    {
                        // Do we have a control to position?
                        if (_viewControl != null)
                        {
                            // Size and position the child control
                            _viewControl.SetBounds(ClientLocation.X, ClientLocation.Y, ClientWidth, ClientHeight);

                            // Ensure the visible/enabled states are up to date
                            _viewControl.Visible = Visible;
                            _viewControl.Enabled = Enabled;

                            // A layout means something might have changed, so better redraw it
                            _viewControl.Invalidate();
                        }
                    }

                    // Adjust the view location to be at the top left of the child control
                    context.DisplayRectangle = new Rectangle(LayoutOffset, ClientSize);

                    // Do we have a child view to layout?
                    if (_viewChild != null)
                    {
                        // Layout the child view
                        _viewChild.Layout(context);
                    }

                    // Put back the original display value now we have finished
                    context.DisplayRectangle = ClientRectangle;
                }
            }
        }