Ejemplo n.º 1
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);

            if (ActiveFormStyle == null || ActiveFormStyle.NormalState.Image == null)
            {
                return;
            }

            Rectangle srcRect =
                DrawUtil.ExcludePadding(new Rectangle(Point.Empty, ActiveFormStyle.NormalState.Image.Size),
                                        ActiveFormStyle.ClientAreaPadding);

            Padding margins =
                DrawUtil.SubstractPadding(ActiveFormStyle.NormalState.StretchMargins, ActiveFormStyle.ClientAreaPadding);

            DrawUtil.DrawImage(e.Graphics, ActiveFormStyle.NormalState.Image, srcRect, ClientRectangle, null, margins);
        }
Ejemplo n.º 2
0
        protected override void OnNonClientAreaPaint(NonClientPaintEventArgs e)
        {
            if (ActiveFormStyle == null)
            {
                return;
            }

            // assign clip region to exclude client area
            Region clipRegion = new Region(e.Bounds);

            clipRegion.Exclude(DrawUtil.ExcludePadding(e.Bounds, ActiveFormStyle.ClientAreaPadding));
            e.Graphics.Clip = clipRegion;

            // paint borders
            ActiveFormStyle.NormalState.DrawImage(e.Graphics, e.Bounds);

            int textOffset = 0;

            // paint icon
            if (ShowIcon &&
                FormBorderStyle != FormBorderStyle.FixedToolWindow &&
                FormBorderStyle != FormBorderStyle.SizableToolWindow)
            {
                Rectangle iconRect = GetIconRectangle();
                textOffset += iconRect.Right;

                if (smallIcon != null)
                {
                    e.Graphics.DrawIconUnstretched(smallIcon, iconRect);
                }
                else
                {
                    e.Graphics.DrawIcon(Icon, iconRect);
                }
            }


            // paint caption
            string text = this.Text;

            if (!String.IsNullOrEmpty(text))
            {
                // disable text wrapping and request elipsis characters on overflow
                using (StringFormat sf = new StringFormat())
                {
                    sf.Trimming      = StringTrimming.EllipsisCharacter;
                    sf.FormatFlags   = StringFormatFlags.NoWrap;
                    sf.LineAlignment = StringAlignment.Center;

                    // find position of the first button from left
                    int firstButton = e.Bounds.Width;
                    foreach (CaptionButton button in this.CaptionButtons)
                    {
                        if (button.Visible)
                        {
                            firstButton = Math.Min(firstButton, button.Bounds.X);
                        }
                    }

                    Padding   padding  = ActiveFormStyle.TitlePadding;
                    Rectangle textRect = new Rectangle(textOffset + padding.Left,
                                                       padding.Top, firstButton - textOffset - padding.Horizontal,
                                                       ActiveFormStyle.ClientAreaPadding.Top - padding.Vertical);

                    Font textFont = this.Font;
                    if (ActiveFormStyle.TitleFont != null)
                    {
                        textFont = ActiveFormStyle.TitleFont;
                    }

                    if (!ActiveFormStyle.TitleShadowColor.IsEmpty)
                    {
                        Rectangle shadowRect = textRect;
                        shadowRect.Offset(1, 1);

                        // draw drop shadow
                        using (Brush b = new SolidBrush(ActiveFormStyle.TitleShadowColor))
                        {
                            e.Graphics.DrawString(text, textFont, b, shadowRect, sf);
                        }
                    }

                    if (!ActiveFormStyle.TitleColor.IsEmpty)
                    {
                        // draw text
                        using (Brush b = new SolidBrush(ActiveFormStyle.TitleColor))
                        {
                            e.Graphics.DrawString(text, textFont, b, textRect, sf);
                        }
                    }
                }
            }

            // paint buttons
            foreach (CaptionButton button in this.CaptionButtons)
            {
                button.DrawButton(e.Graphics, false);
            }
        }