예제 #1
0
        private void NCBeforeBorderPaint(object sender, CustomNCPaintEventArgs e)
        {
            m_TitleArea = Rectangle.Empty;
            // Exclude text area from border rendering
            if (this.Text != null && this.Text.Length > 0)
            {
                Size s = GetAutoSize(this.ClientRectangle.Width - 8);
                Rectangle r = new Rectangle(m_NCPainter.ClientRectangle.X  + 3, 0, s.Width, m_NCPainter.ClientRectangle.Y);
                Size availSize = new Size(m_NCPainter.ClientRectangle.Width - 8, m_NCPainter.ClientRectangle.Y);
                
                    if (m_TitleImage != null && (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.Yes ||
                            m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.No))
                    {
                        //r.X -= m_TitleImage.Width;
                        availSize.Width -= m_TitleImage.Width;
                    }
                    else if (m_TitleImage != null && (m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.Yes ||
                            m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.No))
                    {
                        r.X += m_TitleImage.Width;
                        availSize.Width -= m_TitleImage.Width;
                    }
                //if (this.TextMarkupElement == null)
                {
                    if (this.Style.TextAlignment == eStyleTextAlignment.Center)
                    {
                        //r.X = m_NCPainter.ClientRectangle.X;
                        r.X += (availSize.Width - r.Width) / 2;
                    }
                    else if (this.Style.TextAlignment == eStyleTextAlignment.Far || this.RightToLeft == RightToLeft.Yes && this.Style.TextAlignment == eStyleTextAlignment.Near)
                    {
                        r.X = r.X + (availSize.Width - r.Width);
                    }
                }
                
                if (!r.IsEmpty)
                {
                    r.Inflate(2, 0);
                    r.Width += 3;
                }

                e.Graphics.SetClip(r, System.Drawing.Drawing2D.CombineMode.Exclude);
                m_TitleArea = r;
            }

            if (m_TitleImage != null)
            {
                Rectangle r = new Rectangle(m_NCPainter.ClientRectangle.X + 3, 0, m_TitleImage.Width, m_TitleImage.Height);
                if (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.Yes ||
                    m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.No)
                {
                    r.X = m_NCPainter.ClientRectangle.Right - r.Width - 4;
                }
                else if (m_TitleImagePosition == eTitleImagePosition.Center)
                {
                    r.X = m_NCPainter.ClientRectangle.X;
                    r.X += (m_NCPainter.ClientRectangle.Width - r.Width) / 2;
                }

                e.Graphics.SetClip(r, System.Drawing.Drawing2D.CombineMode.Exclude);
                if (m_TitleArea.IsEmpty)
                    m_TitleArea = r;
                else
                    m_TitleArea = Rectangle.Union(r, m_TitleArea);
            }
        }
예제 #2
0
        private void NCAfterBorderPaint(object sender, CustomNCPaintEventArgs e)
        {
            Graphics g = e.Graphics;

            TextRenderingHint th = g.TextRenderingHint;
            SmoothingMode sm = g.SmoothingMode;
            if (this.AntiAlias)
            {
                g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                g.SmoothingMode = SmoothingMode.AntiAlias;
            }
            g.ResetClip();
            ElementStyle style = this.Style;

            if (!this.Enabled)
            {
                style = style.Copy();
                style.TextColor = GetColorScheme().ItemDisabledText;
            }

            if (m_DrawTitleBox && !m_TitleArea.IsEmpty)
            {
                DisplayHelp.FillRoundedRectangle(g, m_TitleArea, 2, style.BackColor, style.BackColor2, -90);
                DisplayHelp.DrawRoundedRectangle(g, this.Style.BorderColor, m_TitleArea, 2);
            }

            Rectangle rText = new Rectangle(m_NCPainter.ClientRectangle.X + 4, 1, this.ClientRectangle.Width - 8, m_NCPainter.ClientRectangle.Y - 1);
            if (m_TitleImage != null)
            {
                Size textSize = GetAutoSize(rText.Width);
                if (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.No || m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.Yes)
                {
                    g.DrawImage(m_TitleImage, rText.X - 1, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
                    rText.X += m_TitleImage.Width;
                    rText.Width -= m_TitleImage.Width;
                }
                else if (m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.No || m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.Yes)
                {
                    g.DrawImage(m_TitleImage, rText.Right - m_TitleImage.Width, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
                    rText.Width -= m_TitleImage.Width;
                }
                else if (m_TitleImagePosition == eTitleImagePosition.Center)
                {
                    g.DrawImage(m_TitleImage, rText.X + (rText.Width - m_TitleImage.Width) / 2, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
                }
                rText.Y = rText.Bottom - textSize.Height - 2;
            }

            // Paint text
            if (this.TextMarkupElement == null)
            {
                ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, g, rText);
                info.RightToLeft = (this.RightToLeft == RightToLeft.Yes);
                ElementStyleDisplay.PaintText(info, this.Text, this.Font);
            }
            else
            {
                TextRenderingHint tr = g.TextRenderingHint;
                if (this.AntiAlias)
                    g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
                TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, style.TextColor, (this.RightToLeft == RightToLeft.Yes), Rectangle.Empty, true);
                Rectangle r = this.TextMarkupElement.Bounds;
                if (style.TextAlignment == eStyleTextAlignment.Center)
                    this.TextMarkupElement.Bounds = new Rectangle(this.TextMarkupElement.Bounds.X + (rText.Width - this.TextMarkupElement.Bounds.Width) / 2, this.TextMarkupElement.Bounds.Y,
                        this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Height);
                else if(style.TextAlignment == eStyleTextAlignment.Far && this.RightToLeft == RightToLeft.No || this.RightToLeft == RightToLeft.Yes && style.TextAlignment== eStyleTextAlignment.Near)
                    this.TextMarkupElement.Bounds = new Rectangle(rText.Right - this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Y,
                        this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Height);
                this.TextMarkupElement.Render(d);
                g.TextRenderingHint = tr;
                this.TextMarkupElement.Bounds = r;
            }

            g.TextRenderingHint = th;
            g.SmoothingMode = sm;
        }