예제 #1
0
        /// <summary>
        /// Gets a rectangle for the image
        /// </summary>
        RectangleF GetImageRect(Bounds bounds, Image image, TextStyle textStyle)
        {
            SizeF maxSize = bounds.GetSizeF();
            SizeF imgSize = new SizeF(ImageWidth, ImageHeight);

            return(bounds.GetRectangleF(imgSize,
                                        SectionText.ConvertAlign(textStyle.StringAlignment),
                                        textStyle.VerticalAlignment));
        }
예제 #2
0
        /// <summary>
        /// Paints or measures the object passed in according
        /// to the formatting rules of this column.
        /// </summary>
        /// <param name="g">the graphics to paint the value onto</param>
        /// <param name="headerRow">True if this is a header row</param>
        /// <param name="alternatingRow">True if this row is an "alternating" row (even row most likely)</param>
        /// <param name="summaryRow">True if this row is a summary row</param>
        /// <param name="drv">DataRowView to grab the cell from</param>
        /// <param name="x">the x coordinate to start the paint</param>
        /// <param name="y">the y coordinate to start the paint</param>
        /// <param name="width">the width of the cell</param>
        /// <param name="height">The max height of this cell (when in sizeOnly mode)</param>
        /// <param name="sizeOnly">only calculate the sizes</param>
        /// <returns>A sizeF representing the measured size of the string + margins</returns>
        public virtual SizeF SizePaintCell
        (
            Graphics g, bool headerRow, bool alternatingRow, bool summaryRow,
            DataRowView drv, float x, float y, float width,
            float height, bool sizeOnly)
        {
            // TODO: Break up this function
            SizeF        stringSize   = new SizeF(width, height);
            string       text         = GetString(headerRow, summaryRow, drv);
            TextStyle    textStyle    = GetTextStyle(headerRow, alternatingRow, summaryRow);
            Font         font         = textStyle.GetFont();
            StringFormat stringFormat = textStyle.GetStringFormat();

            float  sideMargins      = textStyle.MarginNear + textStyle.MarginFar + RightPenWidth;
            float  topBottomMargins = textStyle.MarginTop + textStyle.MarginBottom;
            Bounds bounds           = new Bounds(x, y, x + width, y + height);
            Bounds innerBounds      = bounds.GetBounds(textStyle.MarginTop,
                                                       textStyle.MarginFar + RightPenWidth, textStyle.MarginBottom, textStyle.MarginNear);
            SizeF maxSize = innerBounds.GetSizeF();

            if (sizeOnly)
            {
                // Find the height of the actual string to be drawn
                stringSize         = g.MeasureString(text, font, maxSize, stringFormat);
                stringSize.Width  += sideMargins;
                stringSize.Height += topBottomMargins;
                // Don't go bigger than maxHeight
                stringSize.Height = Math.Min(stringSize.Height, height);
            }
            else
            {
                // draw background & text
                if (textStyle.BackgroundBrush != null)
                {
                    g.FillRectangle(textStyle.BackgroundBrush, bounds.GetRectangleF());
                }
                RectangleF textLayout = innerBounds.GetRectangleF(stringSize,
                                                                  SectionText.ConvertAlign(textStyle.StringAlignment),
                                                                  textStyle.VerticalAlignment);
                g.DrawString(text, font, textStyle.Brush, textLayout, stringFormat);
            }
            return(stringSize);
        }