Пример #1
0
 /// <summary>
 /// Paints the client rect - e.ClipingRect has the correct window size, since this.Width, this.Height
 /// aren't always correct when calling this methode (because window is actually resizing)
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnNonClientAreaPaint(NonClientPaintEventArgs e)
 {
     e.Graphics.FillRectangle(new SolidBrush(Color.DarkViolet), 0, 0, e.Bounds.Width, e.Bounds.Height);
 }
        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);
            }
        }