/// <summary>
        /// Paint the Text and the Image passed
        /// </summary>
        /// <param name="g">Graphics device where you can render your image and text</param>
        /// <param name="p_displayRectangle">Relative rectangle based on the display area</param>
        /// <param name="p_Image">Image to draw. Can be null.</param>
        /// <param name="p_ImageAlignment">Alignment of the image</param>
        /// <param name="p_ImageStretch">True to make the draw the image with the same size of the cell</param>
        /// <param name="p_Text">Text to draw (can be null)</param>
        /// <param name="p_StringFormat">String format (can be null)</param>
        /// <param name="p_AlignTextToImage">True to align the text with the image</param>
        /// <param name="p_Border">Cell Border</param>
        /// <param name="p_TextColor">Text Color</param>
        /// <param name="p_TextFont">Text Font(can be null)</param>
        /// <param name="p_ExpandedCell">if set to <c>true</c> cell is expanded.</param>
        /// <param name="p_LastExpandedCell">if set to <c>true</c> cell is last expanded cell.</param>
        protected static void PaintImageAndText(Graphics g,
      Rectangle p_displayRectangle,
      Image p_Image,
      ContentAlignment p_ImageAlignment,
      bool p_ImageStretch,
      string p_Text,
      StringFormat p_StringFormat,
      bool p_AlignTextToImage,
      RectangleBorder p_Border,
      Color p_TextColor,
      Font p_TextFont,
      bool p_ExpandedCell,
      bool p_LastExpandedCell)
        {
            // Calculate Rectangle with no border
              Rectangle l_CellRectNoBorder = p_Border.RemoveBorderFromRectangle(p_displayRectangle);

              // Draw image
              if (p_Image != null)
              {
            if (p_ImageStretch) // stretch image
            {
              g.DrawImage(p_Image, l_CellRectNoBorder);
            }
            else
            {
              PointF l_PointImage = CalculateObjAlignment(p_ImageAlignment,
            (int)l_CellRectNoBorder.Left, (int)l_CellRectNoBorder.Top,
            (int)l_CellRectNoBorder.Width, (int)l_CellRectNoBorder.Height,
            p_Image.Width, p_Image.Height);

              RectangleF l_RectDrawImage = l_CellRectNoBorder;
              l_RectDrawImage.Intersect(new RectangleF(l_PointImage, p_Image.PhysicalDimension));

              // Truncate the Rectangle for approximation problem
              g.DrawImage(p_Image, Rectangle.Truncate(l_RectDrawImage));
            }
              }

              // Draw Text
              if (p_Text != null && p_Text.Length > 0)
              {
            if (l_CellRectNoBorder.Width > 0 && l_CellRectNoBorder.Height > 0)
            {
              RectangleF l_RectDrawText = l_CellRectNoBorder;

              // Align Text To Image
              if (p_Image != null && p_ImageStretch == false && p_AlignTextToImage)
              {
            if (AlignmentUtility.IsBottom(p_ImageAlignment) && AlignmentUtility.IsBottom(p_StringFormat))
            {
              l_RectDrawText.Height -= p_Image.Height;
            }
            if (AlignmentUtility.IsTop(p_ImageAlignment) && AlignmentUtility.IsTop(p_StringFormat))
            {
              l_RectDrawText.Y += p_Image.Height;
              l_RectDrawText.Height -= p_Image.Height;
            }
            if (AlignmentUtility.IsLeft(p_ImageAlignment) && AlignmentUtility.IsLeft(p_StringFormat))
            {
              l_RectDrawText.X += p_Image.Width;
              l_RectDrawText.Width -= p_Image.Width;
            }
            if (AlignmentUtility.IsRight(p_ImageAlignment) && AlignmentUtility.IsRight(p_StringFormat))
            {
              l_RectDrawText.Width -= p_Image.Width;
            }
              }

              try
              {
            SolidBrush textBrush = new SolidBrush(p_TextColor);
            g.DrawString(p_Text,
              p_TextFont,
              textBrush,
              l_RectDrawText,
              p_StringFormat);
              }
              catch (Exception ex)
              { // Very long strings can cause a GDI+ exception here.
            LoggerManager.Log(LogLevels.Error, "Cell rendering failed unexpectedly because: " + ex.Message);
              }
            }
              }

              // Draw expanded lines
              if (p_ExpandedCell)
              {
            Pen forePenDark = new Pen(Color.DarkGray, SystemInformation.BorderSize.Height);
            // horizontal line
            Point lineLeft = new Point(l_CellRectNoBorder.Left + (int)((l_CellRectNoBorder.Right - l_CellRectNoBorder.Left) / 2f), l_CellRectNoBorder.Top + (int)((l_CellRectNoBorder.Bottom - l_CellRectNoBorder.Top) / 2f));
            Point lineRight = new Point(l_CellRectNoBorder.Right, (int)(l_CellRectNoBorder.Top + (l_CellRectNoBorder.Bottom - l_CellRectNoBorder.Top) / 2f));
            Point lineTop = new Point(l_CellRectNoBorder.Left + (int)((l_CellRectNoBorder.Right - l_CellRectNoBorder.Left) / 2f), l_CellRectNoBorder.Top);
            Point lineBottom;
            if (p_LastExpandedCell == false)
            {
              lineBottom = new Point(l_CellRectNoBorder.Left + (int)((l_CellRectNoBorder.Right - l_CellRectNoBorder.Left) / 2f), l_CellRectNoBorder.Bottom);
            }
            else
            {
              lineBottom = new Point(l_CellRectNoBorder.Left + (int)((l_CellRectNoBorder.Right - l_CellRectNoBorder.Left) / 2f), l_CellRectNoBorder.Top + (int)((l_CellRectNoBorder.Bottom - l_CellRectNoBorder.Top) / 2f));
            }
            g.DrawLine(forePenDark, lineTop, lineBottom);
            g.DrawLine(forePenDark, lineLeft, lineRight);
              }
        }
示例#2
0
        /// <summary>
        /// Paint the Text and the Image passed
        /// </summary>
        /// <param name="g">Graphics device where you can render your image and text</param>
        /// <param name="p_displayRectangle">Relative rectangle based on the display area</param>
        /// <param name="p_Image">Image to draw. Can be null.</param>
        /// <param name="p_ImageAlignment">Alignment of the image</param>
        /// <param name="p_ImageStretch">True to make the draw the image with the same size of the cell</param>
        /// <param name="p_Text">Text to draw (can be null)</param>
        /// <param name="p_StringFormat">String format (can be null)</param>
        /// <param name="p_AlignTextToImage">True to align the text with the image</param>
        /// <param name="p_Border">Cell Border</param>
        /// <param name="p_TextColor">Text Color</param>
        /// <param name="p_TextFont">Text Font(can be null)</param>
        /// <param name="p_ExpandedCell">if set to <c>true</c> cell is expanded.</param>
        /// <param name="p_LastExpandedCell">if set to <c>true</c> cell is last expanded cell.</param>
        protected static void PaintImageAndText(Graphics g,
                                                Rectangle p_displayRectangle,
                                                Image p_Image,
                                                ContentAlignment p_ImageAlignment,
                                                bool p_ImageStretch,
                                                string p_Text,
                                                StringFormat p_StringFormat,
                                                bool p_AlignTextToImage,
                                                RectangleBorder p_Border,
                                                Color p_TextColor,
                                                Font p_TextFont,
                                                bool p_ExpandedCell,
                                                bool p_LastExpandedCell)
        {
            // Calculate Rectangle with no border
            Rectangle l_CellRectNoBorder = p_Border.RemoveBorderFromRectangle(p_displayRectangle);

            // Draw image
            if (p_Image != null)
            {
                if (p_ImageStretch) // stretch image
                {
                    g.DrawImage(p_Image, l_CellRectNoBorder);
                }
                else
                {
                    PointF l_PointImage = CalculateObjAlignment(p_ImageAlignment,
                                                                (int)l_CellRectNoBorder.Left, (int)l_CellRectNoBorder.Top,
                                                                (int)l_CellRectNoBorder.Width, (int)l_CellRectNoBorder.Height,
                                                                p_Image.Width, p_Image.Height);

                    RectangleF l_RectDrawImage = l_CellRectNoBorder;
                    l_RectDrawImage.Intersect(new RectangleF(l_PointImage, p_Image.PhysicalDimension));

                    // Truncate the Rectangle for approximation problem
                    g.DrawImage(p_Image, Rectangle.Truncate(l_RectDrawImage));
                }
            }

            // Draw Text
            if (p_Text != null && p_Text.Length > 0)
            {
                if (l_CellRectNoBorder.Width > 0 && l_CellRectNoBorder.Height > 0)
                {
                    RectangleF l_RectDrawText = l_CellRectNoBorder;

                    // Align Text To Image
                    if (p_Image != null && p_ImageStretch == false && p_AlignTextToImage)
                    {
                        if (AlignmentUtility.IsBottom(p_ImageAlignment) && AlignmentUtility.IsBottom(p_StringFormat))
                        {
                            l_RectDrawText.Height -= p_Image.Height;
                        }
                        if (AlignmentUtility.IsTop(p_ImageAlignment) && AlignmentUtility.IsTop(p_StringFormat))
                        {
                            l_RectDrawText.Y      += p_Image.Height;
                            l_RectDrawText.Height -= p_Image.Height;
                        }
                        if (AlignmentUtility.IsLeft(p_ImageAlignment) && AlignmentUtility.IsLeft(p_StringFormat))
                        {
                            l_RectDrawText.X     += p_Image.Width;
                            l_RectDrawText.Width -= p_Image.Width;
                        }
                        if (AlignmentUtility.IsRight(p_ImageAlignment) && AlignmentUtility.IsRight(p_StringFormat))
                        {
                            l_RectDrawText.Width -= p_Image.Width;
                        }
                    }

                    try
                    {
                        SolidBrush textBrush = new SolidBrush(p_TextColor);
                        g.DrawString(p_Text,
                                     p_TextFont,
                                     textBrush,
                                     l_RectDrawText,
                                     p_StringFormat);
                    }
                    catch (Exception ex)
                    { // Very long strings can cause a GDI+ exception here.
                        LoggerManager.Log(LogLevels.Error, "Cell rendering failed unexpectedly because: " + ex.Message);
                    }
                }
            }

            // Draw expanded lines
            if (p_ExpandedCell)
            {
                Pen forePenDark = new Pen(Color.DarkGray, SystemInformation.BorderSize.Height);
                // horizontal line
                Point lineLeft  = new Point(l_CellRectNoBorder.Left + (int)((l_CellRectNoBorder.Right - l_CellRectNoBorder.Left) / 2f), l_CellRectNoBorder.Top + (int)((l_CellRectNoBorder.Bottom - l_CellRectNoBorder.Top) / 2f));
                Point lineRight = new Point(l_CellRectNoBorder.Right, (int)(l_CellRectNoBorder.Top + (l_CellRectNoBorder.Bottom - l_CellRectNoBorder.Top) / 2f));
                Point lineTop   = new Point(l_CellRectNoBorder.Left + (int)((l_CellRectNoBorder.Right - l_CellRectNoBorder.Left) / 2f), l_CellRectNoBorder.Top);
                Point lineBottom;
                if (p_LastExpandedCell == false)
                {
                    lineBottom = new Point(l_CellRectNoBorder.Left + (int)((l_CellRectNoBorder.Right - l_CellRectNoBorder.Left) / 2f), l_CellRectNoBorder.Bottom);
                }
                else
                {
                    lineBottom = new Point(l_CellRectNoBorder.Left + (int)((l_CellRectNoBorder.Right - l_CellRectNoBorder.Left) / 2f), l_CellRectNoBorder.Top + (int)((l_CellRectNoBorder.Bottom - l_CellRectNoBorder.Top) / 2f));
                }
                g.DrawLine(forePenDark, lineTop, lineBottom);
                g.DrawLine(forePenDark, lineLeft, lineRight);
            }
        }