Exemple #1
0
 /// <summary>
 /// 构造函数
 /// Initializes a new instance of the CellImageStyle class with default settings
 /// </summary>
 public I3CellImageStyle()
 {
     this.image         = null;
     this.imageSizeMode = I3ImageSizeMode.Normal;
 }
Exemple #2
0
        /// <summary>
        /// Gets the Rectangle that specifies the Size and Location of
        /// the Image contained in the current Cell
        /// </summary>
        /// <param name="image">The Image to be drawn</param>
        /// <param name="sizeMode">An ImageSizeMode that specifies how the
        /// specified Image is scaled</param>
        /// <param name="rowAlignment">The alignment of the current Cell's row</param>
        /// <param name="columnAlignment">The alignment of the current Cell's Column</param>
        /// <returns>A Rectangle that specifies the Size and Location of
        /// the Image contained in the current Cell</returns>
        protected Rectangle CalcImageRect(Image image, I3ImageSizeMode sizeMode, I3RowAlignment rowAlignment, I3ColumnAlignment columnAlignment)
        {
            if (this.DrawText)
            {
                sizeMode = I3ImageSizeMode.ScaledToFit;
            }

            Rectangle imageRect = this.ClientRectangle;

            if (sizeMode == I3ImageSizeMode.Normal)
            {
                if (image.Width < imageRect.Width)
                {
                    imageRect.Width = image.Width;
                }

                if (image.Height < imageRect.Height)
                {
                    imageRect.Height = image.Height;
                }
            }
            else if (sizeMode == I3ImageSizeMode.ScaledToFit)
            {
                if (image.Width >= imageRect.Width || image.Height >= imageRect.Height)
                {
                    double hScale = ((double)imageRect.Width) / ((double)image.Width);
                    double vScale = ((double)imageRect.Height) / ((double)image.Height);

                    double scale = Math.Min(hScale, vScale);

                    imageRect.Width  = (int)(((double)image.Width) * scale);
                    imageRect.Height = (int)(((double)image.Height) * scale);
                }
                else
                {
                    imageRect.Width  = image.Width;
                    imageRect.Height = image.Height;
                }
            }

            if (rowAlignment == I3RowAlignment.Center)
            {
                imageRect.Y += (this.ClientRectangle.Height - imageRect.Height) / 2;
            }
            else if (rowAlignment == I3RowAlignment.Bottom)
            {
                imageRect.Y = this.ClientRectangle.Bottom - imageRect.Height;
            }

            if (!this.DrawText)
            {
                if (columnAlignment == I3ColumnAlignment.Center)
                {
                    imageRect.X += (this.ClientRectangle.Width - imageRect.Width) / 2;
                }
                else if (columnAlignment == I3ColumnAlignment.Right)
                {
                    imageRect.X = this.ClientRectangle.Width - imageRect.Width;
                }
            }

            return(imageRect);
        }