예제 #1
0
        private void RenderImageAndText(Graphics g, Rectangle captionRect)
        {
            Rectangle imageRect  = Rectangle.Empty;
            Rectangle textRect   = Rectangle.Empty;
            int       bordWidth  = base.BorderWidth;
            int       imageWidth = _captionHeight - 6;

            StringFormat sf = new StringFormat();

            sf.FormatFlags = StringFormatFlags.NoWrap;
            sf.Trimming    = StringTrimming.EllipsisCharacter;

            bool rightToLeft = base.RightToLeft == RightToLeft.Yes;

            if (rightToLeft)
            {
                sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            }

            switch (_captionStyle)
            {
            case CaptionStyle.Top:
            case CaptionStyle.Bottom:
                if (_image != null)
                {
                    imageRect = new Rectangle(
                        bordWidth, captionRect.Y + 3, imageWidth, imageWidth);
                }
                else
                {
                    imageRect.X = bordWidth - 3;
                }

                textRect = new Rectangle(
                    imageRect.Right + 3,
                    captionRect.Y,
                    captionRect.Width - (imageRect.Right + 3) - bordWidth,
                    captionRect.Height);

                if (rightToLeft)
                {
                    imageRect.X = captionRect.Right - imageRect.Right;
                    textRect.X  = captionRect.Right - textRect.Right;
                }

                sf.LineAlignment = StringAlignment.Center;

                switch (_textAlign)
                {
                case ContentAlignment.BottomCenter:
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.TopCenter:
                    sf.Alignment = StringAlignment.Center;
                    break;

                case ContentAlignment.BottomLeft:
                case ContentAlignment.MiddleLeft:
                case ContentAlignment.TopLeft:
                    sf.Alignment = StringAlignment.Near;
                    break;

                case ContentAlignment.BottomRight:
                case ContentAlignment.MiddleRight:
                case ContentAlignment.TopRight:
                    sf.Alignment = StringAlignment.Far;
                    break;
                }

                if (!string.IsNullOrEmpty(base.Text))
                {
                    using (Brush brush = new SolidBrush(ColorTable.CaptionFore))
                    {
                        g.DrawString(
                            base.Text,
                            _captionFont,
                            brush,
                            textRect,
                            sf);
                    }
                }
                break;

            case CaptionStyle.Left:
                if (_image != null)
                {
                    imageRect = new Rectangle(
                        captionRect.X + 3, captionRect.Bottom - bordWidth - imageWidth,
                        imageWidth, imageWidth);
                }
                else
                {
                    imageRect.Y = captionRect.Bottom - (bordWidth - 3);
                }

                textRect = new Rectangle(
                    captionRect.X,
                    captionRect.Y + bordWidth,
                    captionRect.Width,
                    imageRect.Y - 3 - bordWidth);

                if (rightToLeft)
                {
                    imageRect.Y = captionRect.Bottom - imageRect.Bottom;
                    textRect.Y  = captionRect.Bottom - textRect.Bottom;
                }

                sf.LineAlignment = StringAlignment.Center;

                switch (_textAlign)
                {
                case ContentAlignment.BottomCenter:
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.TopCenter:
                    sf.Alignment = StringAlignment.Center;
                    break;

                case ContentAlignment.BottomLeft:
                case ContentAlignment.MiddleLeft:
                case ContentAlignment.TopLeft:
                    sf.Alignment = StringAlignment.Near;
                    break;

                case ContentAlignment.BottomRight:
                case ContentAlignment.MiddleRight:
                case ContentAlignment.TopRight:
                    sf.Alignment = StringAlignment.Far;
                    break;
                }
                RenderHelper.RenderVerticalText(
                    g,
                    base.Text,
                    textRect,
                    _captionFont,
                    ColorTable.CaptionFore,
                    sf,
                    true);
                break;

            case CaptionStyle.Right:
                if (_image != null)
                {
                    imageRect = new Rectangle(
                        captionRect.X + 3, bordWidth,
                        imageWidth, imageWidth);
                }
                else
                {
                    imageRect.Y = bordWidth - 3;
                }

                textRect = new Rectangle(
                    captionRect.X,
                    imageRect.Bottom + 3,
                    captionRect.Width,
                    captionRect.Height - (imageRect.Bottom + 3) - bordWidth);

                if (rightToLeft)
                {
                    imageRect.Y = captionRect.Bottom - imageRect.Bottom;
                    textRect.Y  = captionRect.Bottom - textRect.Bottom;
                }

                sf.LineAlignment = StringAlignment.Center;

                switch (_textAlign)
                {
                case ContentAlignment.BottomCenter:
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.TopCenter:
                    sf.Alignment = StringAlignment.Center;
                    break;

                case ContentAlignment.BottomLeft:
                case ContentAlignment.MiddleLeft:
                case ContentAlignment.TopLeft:
                    sf.Alignment = StringAlignment.Near;
                    break;

                case ContentAlignment.BottomRight:
                case ContentAlignment.MiddleRight:
                case ContentAlignment.TopRight:
                    sf.Alignment = StringAlignment.Far;
                    break;
                }
                RenderHelper.RenderVerticalText(
                    g,
                    base.Text,
                    textRect,
                    _captionFont,
                    ColorTable.CaptionFore,
                    sf,
                    false);
                break;
            }

            if (_image != null)
            {
                using (InterpolationModeGraphics ig = new InterpolationModeGraphics(g))
                {
                    g.DrawImage(
                        _image,
                        imageRect,
                        0,
                        0,
                        _image.Width,
                        _image.Height,
                        GraphicsUnit.Pixel);
                }
            }
        }
예제 #2
0
        private void RenderImageAndText(Graphics g, Rectangle captionRect)
        {
            Rectangle imageRect = Rectangle.Empty;
            Rectangle textRect = Rectangle.Empty;
            int bordWidth = base.BorderWidth;
            int imageWidth = _captionHeight - 6;

            StringFormat sf = new StringFormat();
            sf.FormatFlags = StringFormatFlags.NoWrap;
            sf.Trimming = StringTrimming.EllipsisCharacter;

            bool rightToLeft = base.RightToLeft == RightToLeft.Yes;

            if (rightToLeft)
            {
                sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            }

            switch (_captionStyle)
            {
                case CaptionStyle.Top:
                case CaptionStyle.Bottom:
                    if (_image != null)
                    {
                        imageRect = new Rectangle(
                            bordWidth, captionRect.Y + 3, imageWidth, imageWidth);
                    }
                    else
                    {
                        imageRect.X = bordWidth - 3;
                    }

                    textRect = new Rectangle(
                        imageRect.Right + 3,
                        captionRect.Y,
                        captionRect.Width - (imageRect.Right + 3) - bordWidth,
                        captionRect.Height);

                    if (rightToLeft)
                    {
                        imageRect.X = captionRect.Right - imageRect.Right;
                        textRect.X = captionRect.Right - textRect.Right;
                    }

                    sf.LineAlignment = StringAlignment.Center;

                    switch (_textAlign)
                    {
                        case ContentAlignment.BottomCenter:
                        case ContentAlignment.MiddleCenter:
                        case ContentAlignment.TopCenter:
                            sf.Alignment = StringAlignment.Center;
                            break;
                        case ContentAlignment.BottomLeft:
                        case ContentAlignment.MiddleLeft:
                        case ContentAlignment.TopLeft:
                            sf.Alignment = StringAlignment.Near;
                            break;
                        case ContentAlignment.BottomRight:
                        case ContentAlignment.MiddleRight:
                        case ContentAlignment.TopRight:
                            sf.Alignment = StringAlignment.Far;
                            break;
                    }

                    if (!string.IsNullOrEmpty(base.Text))
                    {
                        using(Brush brush = new SolidBrush(ColorTable.CaptionFore))
                        {
                            g.DrawString(
                                base.Text,
                                _captionFont,
                                brush,
                                textRect,
                                sf);
                        }
                    }
                    break;
                case CaptionStyle.Left:
                    if (_image != null)
                    {
                        imageRect = new Rectangle(
                            captionRect.X + 3, captionRect.Bottom - bordWidth - imageWidth,
                            imageWidth, imageWidth);
                    }
                    else
                    {
                        imageRect.Y = captionRect.Bottom - (bordWidth - 3);
                    }

                    textRect = new Rectangle(
                        captionRect.X,
                        captionRect.Y + bordWidth,
                        captionRect.Width,
                        imageRect.Y - 3 - bordWidth);

                    if (rightToLeft)
                    {
                        imageRect.Y = captionRect.Bottom - imageRect.Bottom;
                        textRect.Y = captionRect.Bottom - textRect.Bottom;
                    }

                    sf.LineAlignment = StringAlignment.Center;

                    switch (_textAlign)
                    {
                        case ContentAlignment.BottomCenter:
                        case ContentAlignment.MiddleCenter:
                        case ContentAlignment.TopCenter:
                            sf.Alignment = StringAlignment.Center;
                            break;
                        case ContentAlignment.BottomLeft:
                        case ContentAlignment.MiddleLeft:
                        case ContentAlignment.TopLeft:
                            sf.Alignment = StringAlignment.Near;
                            break;
                        case ContentAlignment.BottomRight:
                        case ContentAlignment.MiddleRight:
                        case ContentAlignment.TopRight:
                            sf.Alignment = StringAlignment.Far;
                            break;
                    }
                    RenderHelper.RenderVerticalText(
                        g,
                        base.Text,
                        textRect,
                        _captionFont,
                        ColorTable.CaptionFore,
                        sf,
                        true);
                    break;
                case CaptionStyle.Right:
                    if (_image != null)
                    {
                        imageRect = new Rectangle(
                            captionRect.X + 3, bordWidth,
                            imageWidth, imageWidth);
                    }
                    else
                    {
                        imageRect.Y = bordWidth - 3;
                    }

                    textRect = new Rectangle(
                        captionRect.X,
                        imageRect.Bottom + 3,
                        captionRect.Width,
                        captionRect.Height - (imageRect.Bottom + 3) - bordWidth);

                    if (rightToLeft)
                    {
                        imageRect.Y = captionRect.Bottom - imageRect.Bottom;
                        textRect.Y = captionRect.Bottom - textRect.Bottom;
                    }

                    sf.LineAlignment = StringAlignment.Center;

                    switch (_textAlign)
                    {
                        case ContentAlignment.BottomCenter:
                        case ContentAlignment.MiddleCenter:
                        case ContentAlignment.TopCenter:
                            sf.Alignment = StringAlignment.Center;
                            break;
                        case ContentAlignment.BottomLeft:
                        case ContentAlignment.MiddleLeft:
                        case ContentAlignment.TopLeft:
                            sf.Alignment = StringAlignment.Near;
                            break;
                        case ContentAlignment.BottomRight:
                        case ContentAlignment.MiddleRight:
                        case ContentAlignment.TopRight:
                            sf.Alignment = StringAlignment.Far;
                            break;
                    }
                    RenderHelper.RenderVerticalText(
                       g,
                       base.Text,
                       textRect,
                       _captionFont,
                       ColorTable.CaptionFore,
                       sf,
                       false);
                    break;
            }

            if (_image != null)
            {
                using (InterpolationModeGraphics ig = new InterpolationModeGraphics(g))
                {
                    g.DrawImage(
                        _image,
                        imageRect,
                        0,
                        0,
                        _image.Width,
                        _image.Height,
                        GraphicsUnit.Pixel);
                }
            }
        }