Ejemplo n.º 1
0
        protected override void OnNonClientAreaPaint(NonClientPaintEventArgs e)
        {
            if (ActiveFormSkin == null)
            {
                return;
            }

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

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

            // paint borders
            ActiveFormSkin.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  = ActiveFormSkin.TitlePadding;
                    Rectangle textRect = new Rectangle(textOffset + padding.Left,
                                                       padding.Top, firstButton - textOffset - padding.Horizontal,
                                                       ActiveFormSkin.ClientAreaPadding.Top - padding.Vertical);

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

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

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

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

            // Translate for the frame border
            //if (this.WindowState == FormWindowState.Maximized)
            //    e.Graphics.TranslateTransform(0, SystemInformation.FrameBorderSize.Height);

            // [2415] Because mouse actions over a button might cause it to repaint we need
            // to buffer the background under the button in order to repaint it correctly.
            // This is important when partially transparent images are used for some button states.
            foreach (CaptionButton button in this.CaptionButtons)
            {
                button.UpdateBackground(e.Graphics, this.Location);
            }

            // Paint all visible buttons (in this case the background doesn't need to be repainted)
            foreach (CaptionButton button in this.CaptionButtons)
            {
                button.DrawButton(e.Graphics, false);
            }
        }
Ejemplo n.º 2
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);
 }