ComponentFactory.Krypton.Toolkit.ViewManager.GetPreferredSize C# (CSharp) Method

GetPreferredSize() public method

Discover the preferred size of the view.
public GetPreferredSize ( IRenderer renderer, Size proposedSize ) : Size
renderer IRenderer Renderer provider.
proposedSize System.Drawing.Size The custom-sized area for a control.
return System.Drawing.Size
        public virtual Size GetPreferredSize(IRenderer renderer,
                                             Size proposedSize)
        {
            if ((renderer == null) || (Root == null))
                return Size.Empty;

            Size retSize = Size.Empty;

            // Short circuit for a disposed control
            if (!_control.IsDisposed)
            {
                // Create a layout context for calculating size and positioning
                using (ViewLayoutContext context = new ViewLayoutContext(this,
                                                                         _control,
                                                                         _alignControl,
                                                                         renderer,
                                                                         proposedSize))
                {
                    retSize = Root.GetPreferredSize(context);
                }
            }

            if (_outputDebug)
            {
                Console.WriteLine("Id:{0} GetPreferredSize Type:{1} Ret:{2} Proposed:{3}",
                    Id,
                    _control.GetType().ToString(),
                    retSize,
                    proposedSize);
            }

            return retSize;
        }

Usage Example

        /// <summary>
        /// Show the tooltip popup relative to the provided screen position.
        /// </summary>
        /// <param name="screenRect">Screen position to display relative to.</param>
        public void ShowCalculatingSize(Rectangle screenRect)
        {
            // Get the size the popup would like to be
            Size popupSize = ViewManager.GetPreferredSize(Renderer, Size.Empty);

            // Find the screen position the popup will be relative to
            screenRect = new Rectangle(screenRect.X, screenRect.Y - VERT_OFFSET,
                                       screenRect.Width, screenRect.Height + (VERT_OFFSET * 2));

            // Show it now!
            Show(screenRect, popupSize);
        }
All Usage Examples Of ComponentFactory.Krypton.Toolkit.ViewManager::GetPreferredSize