Exemplo n.º 1
0
        /// <summary>
        /// Given the <see cref="PanelSizeHints"/>, calculate the best dimensions
        /// for a given number of images
        /// </summary>
        /// <param name="imageCount">Number of images</param>
        /// <param name="sizeHints">hints about the layout</param>
        /// <returns>
        /// The suggested Width (cols) and Height (rows) of the panel as type
        ///  <see cref="System.Drawing.Size"/>
        /// </returns>
        public static Size CalculateBestDimensions(int imageCount,PanelSizeHints sizeHints)
        {
            // in this case we will always scroll (vertically)
            if (imageCount > (8*8)) {
                return new Size(8,8) ;
            }

            if (sizeHints == PanelSizeHints.MinimizeColumns) {
                // divide by max rows
                return new Size(Math.Min((imageCount >> 3) + 1,8),Math.Min(8,imageCount)) ;
            } else if (sizeHints == PanelSizeHints.MinimizeRows) {
                return new Size(Math.Min(8,imageCount),Math.Min((imageCount >> 3) + 1,8)) ;
            }

            int adjust1 = 1 ;
            int adjust2 = 0 ;

            do {
                adjust1++ ;
                adjust2 = (imageCount+(adjust1-1)) / adjust1 ;
            } while(Math.Abs(adjust1-adjust2) > 1) ;

            return new Size(Math.Min(Math.Max(adjust1,adjust2),8),Math.Min(Math.Min(adjust1,adjust2),8)) ;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Show the <c>PSImgPanel</c> as a popup with its origin
        /// at the specified X,Y coordinates (relative to its parent)
        /// with dimensions suggested by the <see cref="PanelSizeHints"/>
        /// </summary>
        /// <param name="x">Left</param>
        /// <param name="y">Top</param>
        /// <param name="placement">Relative meaning of X/Y coordinates</param>
        /// <param name="panelSizeHint">Hint about panel layout</param>
        /// <param name="focusMe">Control to receive the focus when the
        /// popup is complete (or <see langword="null"/>)</param>
        /// <returns>
        /// The image index selected, or -1 if canceled
        /// </returns>
        public int Popup(int x,int y,ImagePanelPlacement placement,Control focusMe,PanelSizeHints panelSizeHint)
        {
            if (Visible) {
                return -1 ;
            }

            Dimensions = CalculateBestDimensions(imageCount,panelSizeHint) ;

            return DoPopup(x,y,placement,focusMe) ;
        }