예제 #1
0
        /// <summary>
        /// ModernToolTipDraw method.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">A System.EventArgs that contains the event data.</param>
        private void ModernToolTipDraw(object sender, DrawToolTipEventArgs e)
        {
            ModernThemeStyle displayTheme = this.ThemeStyle == ModernThemeStyle.Light ? ModernThemeStyle.Dark : ModernThemeStyle.Light;

            Color backColor   = ModernPaint.BackColor.Form(displayTheme);
            Color borderColor = ModernPaint.BorderColor.Button.Normal(displayTheme);
            Color foreColor   = ModernPaint.ForeColor.Label.Normal(displayTheme);

            using (SolidBrush brush = new SolidBrush(backColor))
            {
                e.Graphics.FillRectangle(brush, e.Bounds);
            }

            using (Pen pen = new Pen(borderColor))
            {
                e.Graphics.DrawRectangle(pen, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1));
            }

            Font font = ModernFonts.GetDefaultFont(13f, ModernFontWeight.Regular);

            TextRenderer.DrawText(e.Graphics, e.ToolTipText, font, e.Bounds, foreColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
        }
예제 #2
0
        /// <summary>
        /// OnPaint method.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            Color backColor = this.UseCustomBackColor ? this.BackColor : ModernPaint.BackColor.Form(this.ThemeStyle);
            Color foreColor = this.UseCustomForeColor ? this.ForeColor : ModernPaint.ForeColor.Title(this.ThemeStyle);

            e.Graphics.Clear(backColor);

            if (this.ShowHeader)
            {
                Rectangle       bounds = new Rectangle(20, 20, this.ClientRectangle.Width - (2 * 20), 40);
                TextFormatFlags flags  = TextFormatFlags.EndEllipsis | this.GetTextFormatFlags();
                TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.GetDefaultFont(this.FontSize, this.FontWeight), bounds, foreColor, flags);
            }

            if (this.BackImage != null && this.BackImageMaxSize != 0)
            {
                Image image = ModernImage.ResizeImage(this.BackImage, new Rectangle(0, 0, this.BackImageMaxSize, this.BackImageMaxSize));

                if (this.BackImageInvert)
                {
                    image = ModernImage.ResizeImage(this.ThemeStyle == ModernThemeStyle.Dark ? this._invertBackImage : this.BackImage, new Rectangle(0, 0, this.BackImageMaxSize, this.BackImageMaxSize));
                }

                switch (this.BackImageAlign)
                {
                case ModernFormBackImageAlign.TopLeft:
                    e.Graphics.DrawImage(image, 0 + this.BackImagePadding.Left, 0 + this.BackImagePadding.Top);
                    break;

                case ModernFormBackImageAlign.TopRight:
                    e.Graphics.DrawImage(image, ClientRectangle.Right - (this.BackImagePadding.Right + image.Width), 0 + this.BackImagePadding.Top);
                    break;

                case ModernFormBackImageAlign.BottomLeft:
                    e.Graphics.DrawImage(image, 0 + this.BackImagePadding.Left, ClientRectangle.Bottom - (image.Height + this.BackImagePadding.Bottom));
                    break;

                case ModernFormBackImageAlign.BottomRight:
                    e.Graphics.DrawImage(image, ClientRectangle.Right - (this.BackImagePadding.Right + image.Width), ClientRectangle.Bottom - (image.Height + this.BackImagePadding.Bottom));
                    break;
                }
            }

            if (this.ShowStatusStrip)
            {
                using (SolidBrush brush = ModernPaint.GetStyleBrush(this.ColorStyle))
                {
                    this.StatusStrip.Height   = 20;
                    this.StatusStrip.Width    = this.Width - 20;
                    this.StatusStrip.Location = new Point(0, this.Height - 20);

                    Rectangle bottomRectangle = new Rectangle(0, this.Height - 20, this.Width, 20);
                    e.Graphics.FillRectangle(brush, bottomRectangle);
                }
            }

            if (this.Resizable && (this.SizeGripStyle == SizeGripStyle.Auto || this.SizeGripStyle == SizeGripStyle.Show))
            {
                using (SolidBrush brush = new SolidBrush(ModernPaint.ForeColor.Button.Disabled(this.ThemeStyle)))
                {
                    Size resizeHandleSize = new Size(2, 2);

                    e.Graphics.FillRectangles(
                        brush,
                        new Rectangle[]
                    {
                        new Rectangle(new Point(this.ClientRectangle.Width - 6, this.ClientRectangle.Height - 6), resizeHandleSize),
                        new Rectangle(new Point(this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 10), resizeHandleSize),
                        new Rectangle(new Point(this.ClientRectangle.Width - 10, this.ClientRectangle.Height - 6), resizeHandleSize),
                        new Rectangle(new Point(this.ClientRectangle.Width - 6, this.ClientRectangle.Height - 10), resizeHandleSize),
                        new Rectangle(new Point(this.ClientRectangle.Width - 14, this.ClientRectangle.Height - 6), resizeHandleSize),
                        new Rectangle(new Point(this.ClientRectangle.Width - 6, this.ClientRectangle.Height - 14), resizeHandleSize)
                    });
                }
            }

            if (this.ShowBorder && this.WindowState != FormWindowState.Maximized)
            {
                Color borderColor = ModernPaint.GetStyleColor(this.ColorStyle);

                using (Pen pen = new Pen(borderColor))
                {
                    e.Graphics.DrawLines(
                        pen,
                        new[]
                    {
                        new Point(0, 0),
                        new Point(0, this.Height),
                        new Point(this.Width - 1, this.Height),
                        new Point(this.Width - 1, 0),
                        new Point(0, 0)
                    });
                }
            }
        }