예제 #1
0
        // Token: 0x06002ADE RID: 10974 RVA: 0x000A6234 File Offset: 0x000A4434
        private void method_0(Graphics g, Rectangle bounds)
        {
            Rectangle rectangle;
            Rectangle rectangle2;

            this.method_3(ref bounds, out rectangle, out rectangle2);
            if (base.Image != null)
            {
                if (base.Enabled)
                {
                    g.DrawImage(base.Image, rectangle2.X, rectangle2.Y, base.Image.Width, base.Image.Height);
                }
                else
                {
                    ControlPaint.DrawImageDisabled(g, base.Image, rectangle2.X, rectangle2.Y, this.BackColor);
                }
            }
            if (!base.UseMnemonic)
            {
                this.textFormatFlags_0 |= TextFormatFlags.NoPrefix;
            }
            else if (!this.ShowKeyboardCues)
            {
                this.textFormatFlags_0 |= TextFormatFlags.HidePrefix;
            }
            if (!string.IsNullOrEmpty(this.Text))
            {
                if (base.Enabled)
                {
                    TextRenderer.DrawText(g, this.Text, this.Font, rectangle, this.ForeColor, this.textFormatFlags_0);
                    return;
                }
                ControlPaint.DrawStringDisabled(g, this.Text, this.Font, this.BackColor, rectangle, this.textFormatFlags_0);
            }
        }
예제 #2
0
        private void DrawTabText(Graphics graphics, SolidBrush textBrush, StringFormat format, Rectangle bounds, TabPage page)
        {
            // Set up rotation for left and right aligned tabs.
            if (Alignment == TabAlignment.Left || Alignment == TabAlignment.Right)
            {
                float rotateAngle = 90;
                if (Alignment == TabAlignment.Left)
                {
                    rotateAngle = 270;
                }

                PointF cp = new PointF(bounds.Left + (bounds.Width / 2), bounds.Top + (bounds.Height / 2));
                graphics.TranslateTransform(cp.X, cp.Y);
                graphics.RotateTransform(rotateAngle);

                bounds = new Rectangle(-(bounds.Height / 2), -(bounds.Width / 2), bounds.Height, bounds.Width);
            }

            // Draw the Tab text.
            if (page.Enabled)
            {
                graphics.DrawString(page.Text, Font, textBrush, bounds, format);
            }
            else
            {
                ControlPaint.DrawStringDisabled(graphics, page.Text, Font, textBrush.Color, bounds, format);
            }

            graphics.ResetTransform();
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();

            if ((e.Index < this.Items.Count) && (this.Items.Count > 0) && (e.Index >= 0))
            {
                var   Text   = this.Items[e.Index].ToString();
                Image Bitmap = null;
                if (this.Items[e.Index] is ImageListItem)
                {
                    Bitmap = ((ImageListItem)this.Items[e.Index]).Image;
                }
                int ItemHeight = 0;

                if (e.Index != -1)
                {
                    var TextSize = e.Graphics.MeasureString(Text, this.Font);

                    if (Bitmap != null)
                    {
                        ItemHeight = (int)(Math.Max(TextSize.Height, Bitmap.Height));
                    }
                    else
                    {
                        ItemHeight = (int)TextSize.Height;
                    }

                    // Draw the image in combo box using its bound and ItemHeight
                    if (Bitmap != null)
                    {
                        if (this.Enabled)
                        {
                            e.Graphics.DrawImage(Bitmap, e.Bounds.X, e.Bounds.Y, Bitmap.Height, Bitmap.Height);
                        }
                        else
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, Bitmap, e.Bounds.X, e.Bounds.Y, this.BackColor);
                        }
                    }

                    var StringFormat = new StringFormat()
                    {
                        Trimming = StringTrimming.EllipsisCharacter
                    };
                    var DisabledColor = ControlPaint.Light(SystemColors.WindowText);

                    // We need to draw the item as string because we made drawmode to ownervariable
                    if (this.Enabled)
                    {
                        e.Graphics.DrawString(Text, Font, Brushes.Black, new RectangleF(e.Bounds.X + ItemHeight, e.Bounds.Y, DropDownWidth, ItemHeight));
                    }
                    else
                    {
                        ControlPaint.DrawStringDisabled(e.Graphics, Text, Font, Color.Transparent, new RectangleF(e.Bounds.X + ItemHeight, e.Bounds.Y, DropDownWidth, ItemHeight), StringFormat);
                    }
                }
            }
            // draw rectangle over the item selected
            e.DrawFocusRectangle();
        }
예제 #4
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            //base.OnPaint(pe);

            using (DoubleBuffer buffer = new DoubleBuffer(pe.Graphics, pe.ClipRectangle))
            {
                // paint background
                buffer.Graphics.Clear(BackColor);

                Rectangle imageRect  = new Rectangle(buffer.ClipRectangle.Left, buffer.ClipRectangle.Top, buffer.ClipRectangle.Height, buffer.ClipRectangle.Height);
                Image     imageToUse = Checked ? CheckedImage : UncheckedImage;
                if (imageToUse != null)
                {
                    Image scaledImage = ImageHandling.ScaleImage(imageToUse, imageRect.Width, imageRect.Height);

                    // paint check image
                    if (Enabled)
                    {
                        buffer.Graphics.DrawImage(scaledImage, imageRect.Location);
                    }
                    else
                    {
                        ControlPaint.DrawImageDisabled(buffer.Graphics, scaledImage, imageRect.Left, imageRect.Top, BackColor);
                    }
                }

                Rectangle textRect = new Rectangle(imageRect.Right, buffer.ClipRectangle.Top, buffer.ClipRectangle.Width - imageRect.Width, buffer.ClipRectangle.Height);

                // paint text
                // TODO: fill out stringformat alignment flags\fields according to CheckBox.TextAlign property
                StringFormat format = new StringFormat();
                if (VerticalTextAlignment == VerticalAlignment.Center)
                {
                    format.LineAlignment = StringAlignment.Center;
                }
                else if (VerticalTextAlignment == VerticalAlignment.Top)
                {
                    format.LineAlignment = StringAlignment.Near;
                }
                else if (VerticalTextAlignment == VerticalAlignment.Bottom)
                {
                    format.LineAlignment = StringAlignment.Far;
                }

                if (Enabled)
                {
                    using (SolidBrush textBrush = new SolidBrush(ForeColor))
                    {
                        buffer.Graphics.DrawString(Text, Font, textBrush, textRect, format);
                    }
                }
                else
                {
                    ControlPaint.DrawStringDisabled(buffer.Graphics, Text, Font, BackColor, textRect, format);
                }
            }
        }
예제 #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Black, ButtonBorderStyle.Dashed);
            ControlPaint.DrawSizeGrip(e.Graphics, BackColor, Width - 16, Height - 16, 16, 16);
            var info = string.Format("Ширина : {0} Высота : {1}", Width, Height);
            var size = Size.Round(e.Graphics.MeasureString(info, Font));

            ControlPaint.DrawStringDisabled(e.Graphics, info, Font, Color.Red, new Rectangle(new Point(4, 4), size), StringFormat.GenericDefault);
            base.OnPaint(e);
        }
        /// <summary>
        /// Handles the <see cref="E:Paint" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            StringFormat format = new StringFormat();

            format.Trimming  = StringTrimming.Character;
            format.Alignment = StringAlignment.Near;
            if (this.RightToLeft == RightToLeft.Yes)
            {
                format.FormatFlags = format.FormatFlags | StringFormatFlags.DirectionRightToLeft;
            }

            SizeF stringSize = e.Graphics.MeasureString(Text, Font, ClientRectangle.Size, format);

            if (Enabled)
            {
                Brush br = new SolidBrush(ForeColor);
                e.Graphics.DrawString(Text, Font, br, ClientRectangle, format);
                br.Dispose();
            }
            else
            {
                ControlPaint.DrawStringDisabled(e.Graphics, Text, Font, BackColor, ClientRectangle, format);
            }

            Pen   forePen     = new Pen(ControlPaint.LightLight(BackColor), SystemInformation.BorderSize.Height);
            Pen   forePenDark = new Pen(ControlPaint.Dark(BackColor), SystemInformation.BorderSize.Height);
            Point lineLeft    = new Point(ClientRectangle.Left, ClientRectangle.Top + (int)(Font.Height / 2f));
            Point lineRight   = new Point(ClientRectangle.Right, ClientRectangle.Top + (int)(Font.Height / 2f));

            if (this.RightToLeft != RightToLeft.Yes)
            {
                lineLeft.X += (int)stringSize.Width;
            }
            else
            {
                lineRight.X -= (int)stringSize.Width;
            }

            if (FlatStyle == FlatStyle.Flat)
            {
                e.Graphics.DrawLine(forePenDark, lineLeft, lineRight);
            }
            else
            {
                e.Graphics.DrawLine(forePenDark, lineLeft, lineRight);
                lineLeft.Offset(0, (int)Math.Ceiling((float)SystemInformation.BorderSize.Height / 2f));
                lineRight.Offset(0, (int)Math.Ceiling((float)SystemInformation.BorderSize.Height / 2f));
                e.Graphics.DrawLine(forePen, lineLeft, lineRight);
            }
            forePen.Dispose();
            forePenDark.Dispose();
        }
예제 #7
0
        void DrawText(Graphics g, bool ShowHotKey)
        {
            SolidBrush   TextBrush = new SolidBrush(m_ItemColors.ForeColor);
            StringFormat sf        = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment     = StringAlignment.Near;
            if (ShowHotKey)
            {
                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
            }
            else
            {
                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;
            }

            String ShorCutText = "";

            if (ShowShortcut && Shortcut != Shortcut.None)
            {
                Keys k = (Keys)Shortcut;
                ShorCutText = TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(k);
            }

            if (RTLMenu)
            {
                sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
            }

            if (Parent is MainMenu)
            {
                sf.Alignment = StringAlignment.Center;
            }

            //RectangleF textRectF = RectangleF.FromLTRB(m_TextRect.Left,m_TextRect.Top,m_TextRect.Right,m_TextRect.Bottom);
            if (Enabled)
            {
                g.DrawString(Text, m_Font, TextBrush, m_TextRect, sf);
                sf.Alignment = StringAlignment.Far;
                g.DrawString(ShorCutText, m_Font, TextBrush, m_TextRect, sf);
            }
            else
            {
                ControlPaint.DrawStringDisabled(g, Text, m_Font, m_ItemColors.GradientEndColor, m_TextRect, sf);
                sf.Alignment = StringAlignment.Far;
                ControlPaint.DrawStringDisabled(g, ShorCutText, m_Font, m_ItemColors.GradientEndColor, m_TextRect, sf);
            }

            TextBrush.Dispose();
            sf.Dispose();
        }
예제 #8
0
 protected virtual void PaintTabText(Graphics graphics, Rectangle bounds, NotebookPage page, StringFormat format)
 {
     if (page.Enabled)
     {
         using (Brush textBrush = new SolidBrush(ForeColor))
         {
             graphics.DrawString(page.Text, Font, textBrush, bounds, format);
         }
     }
     else
     {
         ControlPaint.DrawStringDisabled(graphics, page.Text, Font, SystemColors.InactiveCaptionText, bounds, format);
     }
 }
예제 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="g"></param>
 protected void DrawText(Graphics g)
 {
     if (this.Enabled)
     {
         using (SolidBrush brush = new SolidBrush(this.FocusLinkColor)) {
             g.DrawString(this.Text, this.Font, brush, this.TextRect, this.StringFormat);
         }
     }
     else
     {
         // draw disable text the same way as a Label
         ControlPaint.DrawStringDisabled(g, this.Text, this.Font, this.DisabledColor, (RectangleF)this.TextRect, this.StringFormat);
     }
 }
예제 #10
0
        protected override void OnDrawItem(DrawItemEventArgs de)
        {
            Graphics     g   = de.Graphics;
            StringFormat fmt = new StringFormat();
            Brush        brush;
            RectangleF   text_rect = new RectangleF();
            Rectangle    icon_rect;

            fmt.HotkeyPrefix = HotkeyPrefix.Show;


            text_rect.Width    = de.Bounds.Width - 20;
            text_rect.Height   = de.Bounds.Height;
            text_rect.Location = new PointF(16F, (float)de.Bounds.Top + 2);

            if ((de.State & DrawItemState.Selected) > 0)
            {
                g.FillRectangle(SystemBrushes.Highlight, de.Bounds);
                brush = SystemBrushes.HighlightText;
            }
            else
            {
                g.FillRectangle(SystemBrushes.Menu, de.Bounds);
                brush = SystemBrushes.ControlText;
            }

            if ((de.State & DrawItemState.Disabled) > 0)
            {
                ControlPaint.DrawStringDisabled(g,
                                                this.Text,
                                                new Font("Tahoma", 8.25F),
                                                SystemColors.Menu,
                                                text_rect,
                                                fmt);
            }

            else
            {
                g.DrawString(this.Text, new Font("Tahoma", 8.25F), brush, text_rect, fmt);
            }

            if (_icon != null)
            {
                icon_rect = new Rectangle(0, de.Bounds.Y, 16, 16);
                g.DrawIcon(_icon, icon_rect);
            }

            base.OnDrawItem(de);
        }
예제 #11
0
        private void commentTextPaint(object sender, PaintEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("paint");
            //commentText.displayPlaceHolder();

            var color = Color.FromArgb(118, 118, 118);

//			ControlPaint.DrawBorder(e.Graphics, commentBorderPanel.ClientRectangle, color, ButtonBorderStyle.Solid);
            e.Graphics.DrawString("aコメント(75文字以内)", commentPlaceHolderText.Font, new SolidBrush(color), 0, 0);
            var g = e.Graphics;

            g.FillRectangle(new SolidBrush(Color.Green), 0, 0, 100, 100);
            color = Color.FromArgb(229, 229, 229);
            g.DrawString("aコメント(75文字以内)", commentPlaceHolderText.Font, new SolidBrush(color), 1, 1);
            ControlPaint.DrawStringDisabled(g, "aaaaa", commentPlaceHolderText.Font, color, commentPlaceHolderText.ClientRectangle, StringFormat.GenericDefault);
        }
        private void btn_Paint(object sender, PaintEventArgs e)
        {
            var btn = sender as Button;

            if (btn != null)
            {
                var editorBtn = _innerButtons[btn];
                if (editorBtn != null)
                {
                    var imagePoint = new Point(0, 0);
                    var btnImg     = editorBtn.GetImage();
                    if (editorBtn.GetImage() != null)
                    {
                        imagePoint = btn.GetImageLocation(editorBtn.ImageAlign, btnImg);

                        if (editorBtn.Enabled)
                        {
                            e.Graphics.DrawImage(btnImg, new Rectangle(imagePoint, btnImg.Size));
                        }
                        else
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, btnImg, imagePoint.X, imagePoint.Y,
                                                           Color.Transparent);
                        }
                    }
                    if (!string.IsNullOrEmpty(editorBtn.Caption))
                    {
                        var textRect = GetTextRectangle(btn, editorBtn);
                        if (!textRect.IsEmpty)
                        {
                            if (editorBtn.Enabled)
                            {
                                using (Brush brush = new SolidBrush(editorBtn.CaptionColor)) {
                                    e.Graphics.DrawString(editorBtn.Caption, editorBtn.CaptionFont, brush,
                                                          GetTextRectangle(btn, editorBtn));
                                }
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(e.Graphics, editorBtn.Caption, editorBtn.CaptionFont,
                                                                Color.Transparent, GetTextRectangle(btn, editorBtn), TextFormatFlags.Default);
                            }
                        }
                    }
                }
            }
        }
예제 #13
0
        private void PaintTextandImage(Graphics g, Rectangle bounds)
        {
            // Figure out where our text and image should go
            Rectangle text_rectangle;
            Rectangle image_rectangle;

            CalculateButtonTextAndImageLayout(ref bounds, out text_rectangle, out image_rectangle);

            //draw the image
            if (Image != null)
            {
                if (Enabled)
                {
                    g.DrawImage(Image, image_rectangle.X, image_rectangle.Y, Image.Width, Image.Height);
                }
                else
                {
                    ControlPaint.DrawImageDisabled(g, Image, image_rectangle.X, image_rectangle.Y, BackColor);
                }
            }

            // If we dont' use mnemonic, set formatFlag to NoPrefix as this will show ampersand.
            if (!UseMnemonic)
            {
                textFormatFlags = textFormatFlags | TextFormatFlags.NoPrefix;
            }
            else if (!ShowKeyboardCues)
            {
                textFormatFlags = textFormatFlags | TextFormatFlags.HidePrefix;
            }

            //draw the text
            if (!string.IsNullOrEmpty(Text))
            {
                if (Enabled)
                {
                    TextRenderer.DrawText(g, Text, Font, text_rectangle, ForeColor, textFormatFlags);
                }

                else
                {
                    ControlPaint.DrawStringDisabled(g, Text, Font, BackColor, text_rectangle, textFormatFlags);
                }
            }
        }
예제 #14
0
        private void DrawText(object sender, DrawItemEventArgs e, bool isSelected)
        {
            string shortcutText = ShortcutToString(((MenuItem)sender).Shortcut);

            int  yPos = e.Bounds.Top + (e.Bounds.Height - SystemFonts.MenuFont.Height) / 2;
            Size textSize;

            Font font = ((MenuItem)sender).DefaultItem ? new Font(SystemFonts.MenuFont, FontStyle.Bold) : SystemFonts.MenuFont;

            textSize = TextRenderer.MeasureText(((MenuItem)sender).Text, font, new Size(0, 0), TextFormatFlags.SingleLine);

            //Draw the menu item text
            if (((MenuItem)sender).Enabled)
            {
                TextRenderer.DrawText(e.Graphics, ((MenuItem)sender).Text, SystemFonts.MenuFont,
                                      new Rectangle(e.Bounds.Left + LEFT_MARGIN + ICON_SIZE + RIGHT_MARGIN, yPos, textSize.Width, textSize.Height),
                                      isSelected ? SystemColors.HighlightText : SystemColors.MenuText,
                                      TextFormatFlags.SingleLine | (isUsingKeyboardAccel ? 0 : TextFormatFlags.HidePrefix));
            }
            else
            {
                ControlPaint.DrawStringDisabled(e.Graphics, ((MenuItem)sender).Text, SystemFonts.MenuFont, isSelected ? SystemColors.Highlight : SystemColors.Menu,
                                                new Rectangle(e.Bounds.Left + LEFT_MARGIN + ICON_SIZE + RIGHT_MARGIN, yPos, textSize.Width, textSize.Height),
                                                TextFormatFlags.SingleLine | (isUsingKeyboardAccel ? 0 : TextFormatFlags.HidePrefix));
            }

            //Draw the shortcut text
            if (shortcutText != null)
            {
                textSize = TextRenderer.MeasureText(shortcutText, SystemFonts.MenuFont, Size.Empty, TextFormatFlags.SingleLine);

                if (((MenuItem)sender).Enabled)
                {
                    TextRenderer.DrawText(e.Graphics, shortcutText, SystemFonts.MenuFont,
                                          new Rectangle(e.Bounds.Width - textSize.Width - ARROW_MARGIN, yPos, textSize.Width, textSize.Height),
                                          isSelected ? SystemColors.HighlightText : SystemColors.MenuText,
                                          TextFormatFlags.SingleLine);
                }
                else
                {
                    ControlPaint.DrawStringDisabled(e.Graphics, shortcutText, SystemFonts.MenuFont, isSelected ? SystemColors.Highlight : SystemColors.Menu,
                                                    new Rectangle(e.Bounds.Width - textSize.Width - ARROW_MARGIN, yPos, textSize.Width, textSize.Height), TextFormatFlags.SingleLine);
                }
            }
        }
예제 #15
0
        public override void Render(Graphics g)
        {
            base.Render(g);

            if (BackColor != null)
            {
                g.FillRectangle(new SolidBrush(BackColor), this.Bound);
            }

            if (!this.ReadOnly)
            {
                g.DrawString(this.ValueText, this.Font, TextBrush, this.Bound, Format);
            }
            else
            {
                ControlPaint.DrawStringDisabled(g, this.ValueText, this.Font, SystemColors.Control, this.Bound, Format);
            }
        }
예제 #16
0
        public virtual void Draw(Graphics dc, Rectangle_ client_rectangle, Label label)
        {
            Rectangle_ rect = label.PaddingClientRectangle;

            label.DrawImage(dc, label.Image, rect, label.ImageAlign);

            if (label.Enabled)
            {
                dc.DrawString(label.Text, label.Font,
                              ThemeEngine.Current.ResPool.GetSolidBrush(label.ForeColor),
                              rect, label.string_format);
            }
            else
            {
                ControlPaint.DrawStringDisabled(
                    dc, label.Text, label.Font, label.BackColor, rect, label.string_format);
            }
        }
예제 #17
0
파일: MGroupBox.cs 프로젝트: ywscr/MomoForm
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics  graphics        = e.Graphics;
            Rectangle clientRectangle = base.ClientRectangle;
            Color     disabledColor   = Color.FromArgb(189, 195, 199);
            Pen       pen2            = new Pen(this.BorderColor == Color.Empty ? Color.White : this.BorderColor);

            try
            {
                Size size;
                using (Brush brush = new SolidBrush(this.TitleColor))
                {
                    using (StringFormat format = new StringFormat())
                    {
                        size = Size.Ceiling(graphics.MeasureString(this.Text, this.TitleFont, clientRectangle.Width, format));
                        clientRectangle.X      = (this.Width - size.Width - 20) / 2 + 10;
                        clientRectangle.Width  = size.Width + 20;
                        clientRectangle.Height = size.Height;
                        clientRectangle.Y      = 10;
                        if (base.Enabled)
                        {
                            graphics.DrawString(this.Text, this.TitleFont, brush, clientRectangle, format);
                        }
                        else
                        {
                            ControlPaint.DrawStringDisabled(graphics, this.Text, this.TitleFont, disabledColor, clientRectangle, format);
                        }
                    }
                }

                int top = base.FontHeight / 2 + 10;
                //graphics.DrawLine(pen2, 0, top, base.Width, top);// 上边线
                graphics.DrawLine(pen2, 1, top, clientRectangle.X - 10, top);                                      // 上边线
                graphics.DrawLine(pen2, clientRectangle.X + clientRectangle.Width - 10, top, base.Width - 2, top); // 上边线

                graphics.DrawLine(pen2, 1, base.Height - 2, base.Width - 2, base.Height - 2);                      //底部
                graphics.DrawLine(pen2, base.Width - 2, top, base.Width - 2, base.Height - 2);                     //右边
                graphics.DrawLine(pen2, 1, top, 1, base.Height - 2);                                               //左边
            }
            finally
            {
                pen2.Dispose();
            }
        }
        /// <summary>
        /// Draws a single week header element.
        /// </summary>
        /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
        /// <param name="week">The <see cref="MonthCalendarWeek"/> to draw.</param>
        public override void DrawWeekHeaderItem(Graphics g, MonthCalendarWeek week)
        {
            if (!CheckParams(g, week.Bounds))
            {
                return;
            }

            var weekString = this.monthCal.UseNativeDigits
            ? DateMethods.GetNativeNumberString(week.WeekNumber, this.monthCal.Culture.NumberFormat.NativeDigits, false)
            : week.WeekNumber.ToString(CultureInfo.CurrentUICulture);

            // draw week header element
            using (StringFormat format = GetStringAlignment(this.monthCal.DayTextAlignment))
            {
                // set alignment
                format.Alignment = StringAlignment.Center;

                // draw string
                using (SolidBrush brush = new SolidBrush(this.ColorTable.WeekHeaderText))
                {
                    if (this.monthCal.Enabled)
                    {
                        g.DrawString(
                            weekString,
                            this.monthCal.Font,
                            brush,
                            week.Bounds,
                            format);
                    }
                    else
                    {
                        ControlPaint.DrawStringDisabled(
                            g,
                            weekString,
                            this.monthCal.Font,
                            Color.Transparent,
                            week.Bounds,
                            format);
                    }
                }
            }
        }
 protected void DrawText(Graphics g, Rectangle textRect)
 {
     if (!string.IsNullOrEmpty(Text))
     {
         using (var sf = GetStringFormat())
         {
             if (Enabled)
             {
                 using (var brush = new SolidBrush(ForeColor))
                 {
                     g.DrawString(Text, Font, brush, textRect, sf);
                 }
             }
             else
             {
                 ControlPaint.DrawStringDisabled(g, Text, Font, SystemColors.ControlLight, textRect, sf);
             }
         }
     }
 }
예제 #20
0
        /// <summary>
        /// 绘制文本
        /// </summary>
        /// <param name="graphics">绘制对象</param>
        /// <param name="text">绘制文本</param>
        /// <param name="font">字体</param>
        /// <param name="forcolor">字体颜色</param>
        /// <param name="align">文本对齐方式</param>
        /// <param name="enabled">是否为可用样式</param>
        /// <param name="showEllipsis">是否显示省略号</param>
        /// <param name="bounds">绘制区域边界</param>
        /// <param name="padding">绘制区域内边界</param>
        protected static void DrawText(
            Graphics graphics,
            string text,
            Font font,
            Color forcolor,
            ContentAlignment align,
            bool enabled,
            bool showEllipsis,
            Rectangle bounds,
            Padding padding
            )
        {
            if (bounds.Width <= 0 || bounds.Height <= 0)
            {
                return;
            }

            using (StringFormat stringFormat = CreateStringFormat(align, showEllipsis))
            {
                //根据内边距调整绘制区域
                bounds.Offset(padding.Left, padding.Top);
                bounds.Inflate(-padding.Horizontal, -padding.Vertical);
                if (bounds.Width <= 0 || bounds.Height <= 0)
                {
                    return;
                }

                if (enabled)
                {
                    using (Brush brush = new SolidBrush(forcolor))
                    {
                        graphics.DrawString(text, font, brush, bounds, stringFormat);
                    }
                }
                else
                {
                    //绘制禁用样式的文本,可传入禁用样式的字体颜色
                    ControlPaint.DrawStringDisabled(graphics, text, font, Color.Gray, bounds, stringFormat);
                }
            }
        }
        void DrawButtonWithoutVisualStyles(PaintEventArgs e)
        {
            ControlPaint.DrawButton(e.Graphics, HeaderRect, ButtonState);

            if (Enabled)
            {
                using var textBrush = new SolidBrush(ForeColor);
                e.Graphics.DrawString(Text, Font, textBrush, TextRect);
                e.Graphics.DrawImageUnscaledAndClipped(ButtonImage, ImageRect);
            }
            else
            {
                using var format = GetStringFormat();
                ControlPaint.DrawStringDisabled(e.Graphics, Text, Font, BackColor, TextRect, format);
                ControlPaint.DrawImageDisabled(e.Graphics, ButtonImage, ImageRect.Left, ImageRect.Top, BackColor);
            }

            if (Focused && ShowFocusCues)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, FocusRect);
            }
        }
        /// <summary>
        /// Draws a single week header element.
        /// </summary>
        /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
        /// <param name="week">The <see cref="MonthCalendarWeek"/> to draw.</param>
        public override void DrawWeekHeaderItem(Graphics g, MonthCalendarWeek week)
        {
            if (!CheckParams(g, week.Bounds))
            {
                return;
            }

            // draw week header element
            using (StringFormat format = GetStringAlignment(this.monthCal.DayTextAlignment))
            {
                // set alignment
                format.Alignment = StringAlignment.Center;

                // draw string
                using (SolidBrush brush = new SolidBrush(this.ColorTable.WeekHeaderText))
                {
                    if (this.monthCal.Enabled)
                    {
                        g.DrawString(
                            week.WeekNumber.ToString(),
                            this.monthCal.Font,
                            brush,
                            week.Bounds,
                            format);
                    }
                    else
                    {
                        ControlPaint.DrawStringDisabled(
                            g,
                            week.WeekNumber.ToString(),
                            this.monthCal.Font,
                            Color.Transparent,
                            week.Bounds,
                            format);
                    }
                }
            }
        }
예제 #23
0
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            base.ItemHeight = GetPreferredSize(Size.Empty).Height;

            Color borderColor, foreColor;

            if (isHovered && !isPressed && Enabled)
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Hover(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Hover(Theme);
            }
            else if (isHovered && isPressed && Enabled)
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Press(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Press(Theme);
            }
            else if (!Enabled)
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Disabled(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Disabled(Theme);
            }
            else
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Normal(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Normal(Theme);
            }

            using (Pen p = new Pen(borderColor))
            {
                Rectangle boxRect = new Rectangle(0, 0, Width - 1, Height - 1);
                e.Graphics.DrawRectangle(p, boxRect);
            }


            if (DropDownStyle != ComboBoxStyle.Simple)
            {
                using (SolidBrush b = new SolidBrush(foreColor))
                {
                    e.Graphics.FillPolygon(b, new Point[] { new Point(Width - 20, (Height / 2) - 2), new Point(Width - 9, (Height / 2) - 2), new Point(Width - 15, (Height / 2) + 4) });
                }

                Rectangle textRect = new Rectangle(2, 2, Width - 40, Height - 4);

                if (Enabled)
                {
                    TextRenderer.DrawText(e.Graphics, Text, MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                }
                else
                {
                    ControlPaint.DrawStringDisabled(e.Graphics, Text, MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), MetroPaint.ForeColor.ComboBox.Disabled(Theme), textRect, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                }

                OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics));
                if (displayFocusRectangle && isFocused)
                {
                    ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
                }

                if (drawPrompt)
                {
                    DrawTextPrompt(e.Graphics);
                }
            }
        }
예제 #24
0
        private void DrawText(Graphics g)
        {
            SolidBrush TextBrush = new SolidBrush(this.ForeColor);

            RectangleF R = (RectangleF)contentRect;

            if (!this.Enabled)
                TextBrush.Color = SystemColors.GrayText;

            StringFormat sf = new StringFormat(StringFormatFlags.NoWrap | StringFormatFlags.NoClip);

            if (ShowKeyboardCues)
                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
            else
                sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;

            switch (this.TextAlign)
            {
                case ContentAlignment.TopLeft:
                    sf.Alignment = StringAlignment.Near;
                    sf.LineAlignment = StringAlignment.Near;
                    break;

                case ContentAlignment.TopCenter:
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Near;
                    break;

                case ContentAlignment.TopRight:
                    sf.Alignment = StringAlignment.Far;
                    sf.LineAlignment = StringAlignment.Near;
                    break;

                case ContentAlignment.MiddleLeft:
                    sf.Alignment = StringAlignment.Near;
                    sf.LineAlignment = StringAlignment.Center;
                    break;

                case ContentAlignment.MiddleCenter:
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;
                    break;

                case ContentAlignment.MiddleRight:
                    sf.Alignment = StringAlignment.Far;
                    sf.LineAlignment = StringAlignment.Center;
                    break;

                case ContentAlignment.BottomLeft:
                    sf.Alignment = StringAlignment.Near;
                    sf.LineAlignment = StringAlignment.Far;
                    break;

                case ContentAlignment.BottomCenter:
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Far;
                    break;

                case ContentAlignment.BottomRight:
                    sf.Alignment = StringAlignment.Far;
                    sf.LineAlignment = StringAlignment.Far;
                    break;
            }

            if (this.ButtonState == CustomButtonState.Pressed)
                R.Offset(1, 1);

            if (this.Enabled)
                g.DrawString(this.Text, this.Font, TextBrush, R, sf);
            else
                ControlPaint.DrawStringDisabled(g, this.Text, this.Font, this.BackColor, R, sf);

        }
예제 #25
0
파일: TabControl.cs 프로젝트: wonst719/MORT
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.Clear(BackColor);
            Rectangle r = ClientRectangle;

            if (TabCount <= 0)
            {
                return;
            }
            //Draw a custom background for Transparent TabPages
            r = SelectedTab.Bounds;


            StringFormat sf = new StringFormat();

            //sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            Font textFont = Font;

            //Draw a border around TabPage
            r.Inflate(4, 23);

            TabPage tp = TabPages[SelectedIndex];
            //SolidBrush PaintBrush = new SolidBrush(tp.BackColor)

            SolidBrush PaintBrush = new SolidBrush(Color.FromArgb(35, 36, 38));

            e.Graphics.FillRectangle(PaintBrush, r);


            //ControlPaint.DrawBorder(e.Graphics, r, PaintBrush.Color, ButtonBorderStyle.None);

            //Draw the Tabs
            for (int index = 0; index <= TabCount - 1; index++)
            {
                tp = TabPages[index];
                r  = GetTabRect(index);
                ButtonBorderStyle bs = ButtonBorderStyle.None;
                SolidBrush        textBrush;

                if (index == SelectedIndex)
                {
                    bs        = ButtonBorderStyle.None;
                    textBrush = new SolidBrush(Color.Gainsboro);
                    textFont  = new Font(Font, FontStyle.Underline);
                }
                else
                {
                    textBrush = new SolidBrush(Color.White);
                    textFont  = new Font(Font, FontStyle.Regular);
                }
                r.X -= 3;
                PaintBrush.Color = tp.BackColor;
                e.Graphics.FillRectangle(PaintBrush, r);//이곳에서 배경색을 바꿈
                ControlPaint.DrawBorder(e.Graphics, r, PaintBrush.Color, bs);
                PaintBrush.Color = tp.ForeColor;

                //Set up rotation for left and right aligned tabs

                /*
                 * if (Alignment == TabAlignment.Left || Alignment == TabAlignment.Right)
                 * {
                 *  float RotateAngle = 90;
                 *  if (Alignment == TabAlignment.Left) RotateAngle = 270;
                 *  PointF cp = new PointF(r.Left + (r.Width >> 1), r.Top + (r.Height >> 1));
                 *  e.Graphics.TranslateTransform(cp.X, cp.Y);
                 *  e.Graphics.RotateTransform(RotateAngle);
                 *  r = new Rectangle(-(r.Height >> 1), -(r.Width >> 1), r.Height, r.Width);
                 *
                 * }
                 */
                r.Location = new Point(r.Location.X + 10, r.Location.Y);
                //Draw the Tab Text
                if (tp.Enabled)
                {
                    e.Graphics.DrawString(tp.Text, textFont, textBrush, (RectangleF)r, sf);
                }
                else
                {
                    ControlPaint.DrawStringDisabled(e.Graphics, tp.Text, textFont, tp.BackColor, (RectangleF)r, sf);
                }

                e.Graphics.ResetTransform();
            }

            PaintBrush.Dispose();
        }
예제 #26
0
        public void DrawTask(Graphics g, int itemIndex, Rectangle r, bool forceDisabled, bool showsettings = false)
        {
            if (itemIndex > -1 && itemIndex < Items.Count)
            {
                AbstractProcessingTask task = Items[itemIndex] as AbstractProcessingTask;
                if (task == null)
                {
                    return;
                }
                bool disabled = !GetTaskEnabled(task) || forceDisabled;
                using (SolidBrush backgroundBrush = new SolidBrush(SkinInfo.BackColor))
                {
                    // Draw the background
                    g.FillRectangle(backgroundBrush, r);
                    int bitmapSize  = Math.Min(r.Width, r.Height);
                    int imageOffset = 0;
                    using (Image inImage = GetImage(task.In))
                    {
                        using (Image outImage = GetImage(task.Out))
                        {
                            DrawScaleImage(g, r.Location, inImage, bitmapSize, !disabled, SkinInfo.FadedColorMatrix);
                            r.X     += bitmapSize * 3 / 4;
                            r.Width -= bitmapSize * 3 / 4;

                            DrawScaleImage(g, r.Location, outImage, bitmapSize, !disabled, SkinInfo.FadedColorMatrix);

                            r.X     += bitmapSize;
                            r.Width -= bitmapSize;
                            using (Image taskImage = GetImage(task.TaskType))
                            {
                                Point p = new Point((int)(r.X - bitmapSize * 1.35), r.Y);
                                DrawScaleImage(g, p, taskImage, bitmapSize, !disabled, SkinInfo.HoverColorMatrix);
                            }
                        }

                        if (r.Width <= 0)
                        {
                            return;
                        }
                        if (showsettings && task.HasSettings)
                        {
                            DrawScaleImage(g, new Point(r.Right - bitmapSize, r.Top), global::Sardauscan.Properties.Resources.Gears, bitmapSize, true);
                        }
                        r.Width -= bitmapSize;
                        if (r.Width <= 0)
                        {
                            return;
                        }

                        r = task.DrawStatus(g, r, SkinInfo.BackColor, SkinInfo.ForeColor);
                        if (r.Width <= 0)
                        {
                            return;
                        }
                        Color textColor = SkinInfo.ForeColor.GetStepColor(SkinInfo.BackColor, this.Lock ? 0.5 : 0);
                        if (!task.Ready)
                        {
                            textColor = Color.Red;
                        }
                        using (SolidBrush TextBrush = new SolidBrush(textColor))
                        {
                            StringFormat sf = new StringFormat(StringFormatFlags.NoWrap | StringFormatFlags.NoClip);
                            sf.Alignment     = StringAlignment.Near;
                            sf.LineAlignment = StringAlignment.Center;
                            Rectangle textRect = new Rectangle(r.X + imageOffset, r.Y + 0, r.Width - imageOffset, r.Height);
                            string    text     = task.DisplayName;
                            if (this.Enabled)
                            {
                                g.DrawString(text, this.Font, TextBrush, textRect, sf);
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(g, text, this.Font, backgroundBrush.Color, textRect, sf);
                            }
                        }
                    }
                }
            }
        }
예제 #27
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (TabCount <= 0)
            {
                return;
            }

            // clear the initial color
            e.Graphics.Clear(BackColor);

            //Draw a custom background for Transparent TabPages
            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Far;

            Rectangle  r = ClientRectangle;
            TabPage    tp;
            SolidBrush PaintBrush      = new SolidBrush(BackColor);
            SolidBrush SelectedBrush   = new SolidBrush(Color.White);
            Pen        BorderPenBottom = new Pen(Color.FromArgb(112, 151, 180));
            Pen        BorderPenTop    = new Pen(Color.FromArgb(149, 178, 199));


            //Draw the Tabs
            for (int index = 0; index <= TabCount - 1; index++)
            {
                tp = TabPages[index];
                r  = GetTabRect(index);

                ButtonBorderStyle bs = ButtonBorderStyle.None;

                // draw the border to seemless
                ControlPaint.DrawBorder(e.Graphics, r, PaintBrush.Color, bs);

                if (index == SelectedIndex)
                {
                    // draw different color for the selected tab
                    int x = 2;
                    int y = 0;
                    if (index == 0)
                    {
                        y = -2;
                    }
                    r.Inflate(x, y);
                    e.Graphics.FillRectangle(SelectedBrush, r);
                    r.Inflate(-x, -y);
                }

                // draw the bottom line of the tab
                if (index != 0)
                {
                    e.Graphics.DrawLine(BorderPenTop, new Point(r.Left, r.Top), new Point(r.Right, r.Top));
                }

                e.Graphics.DrawLine(BorderPenBottom, new Point(r.Left, r.Bottom), new Point(r.Right, r.Bottom));

                PaintBrush.Color = tp.ForeColor;

                //Set up rotation for left and right aligned tabs
                if (Alignment == TabAlignment.Left || Alignment == TabAlignment.Right)
                {
                    PointF cp = new PointF(r.Left + (r.Width >> 1), r.Top + (r.Height >> 1));
                    e.Graphics.TranslateTransform(cp.X, cp.Y);
                    r = new Rectangle(-(r.Height >> 1), -(r.Width >> 1), r.Height, r.Width);
                }

                //Draw the Tab Text
                if (tp.Enabled)
                {
                    e.Graphics.DrawString(tp.Text, Font, PaintBrush, (RectangleF)r, sf);
                }
                else
                {
                    ControlPaint.DrawStringDisabled(e.Graphics, tp.Text, Font, tp.BackColor, (RectangleF)r, sf);
                }

                // draw the tab image
                Image tabImage = null;
                if (this.ImageList != null)
                {
                    TabPage page = this.TabPages[index];
                    if (page.ImageIndex > -1 && page.ImageIndex < this.ImageList.Images.Count)
                    {
                        tabImage = this.ImageList.Images[page.ImageIndex];
                    }

                    if (page.ImageKey.Length > 0 && this.ImageList.Images.ContainsKey(page.ImageKey))
                    {
                        tabImage = this.ImageList.Images[page.ImageKey];
                    }

                    using (Bitmap bm = new Bitmap(r.Width, r.Height))
                    {
                        using (Graphics bmGraphics = Graphics.FromImage(bm))
                        {
                            if (tabImage != null)
                            {
                                Rectangle imageRect = new Rectangle(0, 0, tabImage.Width, tabImage.Height);
                                imageRect.Offset((r.Width - imageRect.Width) / 2, (r.Height - imageRect.Height) / 2);
                                bmGraphics.DrawImage(tabImage, imageRect);
                            }
                        }

                        e.Graphics.DrawImage(bm, r);
                    }
                }

                e.Graphics.ResetTransform();
            }

            BorderPenBottom.Dispose();
            PaintBrush.Dispose();
            SelectedBrush.Dispose();
        }
예제 #28
0
        private Size MeasureAndDraw(Graphics g, bool enableDrawing, PushButtonState state, bool drawFocusCues, bool drawKeyboardCues)
        {
            if (enableDrawing)
            {
                g.PixelOffsetMode   = PixelOffsetMode.Half;
                g.CompositingMode   = CompositingMode.SourceOver;
                g.InterpolationMode = InterpolationMode.Bilinear;
            }

            int marginX       = UI.ScaleWidth(9);
            int marginYTop    = UI.ScaleHeight(8);
            int marginYBottom = UI.ScaleHeight(9);
            int paddingX      = UI.ScaleWidth(8);
            int paddingY      = UI.ScaleHeight(3);
            int offsetX       = 0;
            int offsetY       = 0;

            bool drawAsDefault = (state == PushButtonState.Default);

            if (enableDrawing)
            {
                using (Brush backBrush = new SolidBrush(this.BackColor))
                {
                    CompositingMode oldCM = g.CompositingMode;
                    g.CompositingMode = CompositingMode.SourceCopy;
                    g.FillRectangle(backBrush, ClientRectangle);
                    g.CompositingMode = oldCM;
                }

                Rectangle ourRect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height);

                if (state == PushButtonState.Pressed)
                {
                    offsetX = 1;
                    offsetY = 1;
                }

                UI.DrawCommandButton(g, state, ourRect, BackColor, this);
            }

            Rectangle actionImageRect;

            Brush textBrush = new SolidBrush(SystemColors.WindowText);

            if (this.actionImage == null)
            {
                actionImageRect = new Rectangle(offsetX, offsetY + marginYTop, 0, 0);
            }
            else
            {
                actionImageRect = new Rectangle(offsetX + marginX, offsetY + marginYTop,
                                                UI.ScaleWidth(this.actionImage.Width), UI.ScaleHeight(this.actionImage.Height));

                Rectangle srcRect = new Rectangle(0, 0, this.actionImage.Width, this.actionImage.Height);

                if (enableDrawing)
                {
                    Image drawMe = Enabled ? this.actionImage : this.actionImageDisabled;

                    if (Enabled)
                    {
                        actionImageRect.Y += 3;
                        actionImageRect.X += 1;
                        g.DrawImage(this.actionImageDisabled, actionImageRect, srcRect, GraphicsUnit.Pixel);
                        actionImageRect.X -= 1;
                        actionImageRect.Y -= 3;
                    }

                    actionImageRect.Y += 2;
                    g.DrawImage(drawMe, actionImageRect, srcRect, GraphicsUnit.Pixel);
                    actionImageRect.Y -= 2;
                }
            }

            int actionTextX     = actionImageRect.Right + paddingX;
            int actionTextY     = actionImageRect.Top;
            int actionTextWidth = ClientSize.Width - actionTextX - marginX + offsetX;

            StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone();

            stringFormat.HotkeyPrefix = drawKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide;

            SizeF actionTextSize = g.MeasureString(this.actionText, this.actionTextFont, actionTextWidth, stringFormat);

            Rectangle actionTextRect = new Rectangle(actionTextX, actionTextY,
                                                     actionTextWidth, (int)Math.Ceiling(actionTextSize.Height));

            if (enableDrawing)
            {
                if (state == PushButtonState.Disabled)
                {
                    ControlPaint.DrawStringDisabled(g, this.actionText, this.actionTextFont, this.BackColor, actionTextRect, stringFormat);
                }
                else
                {
                    g.DrawString(this.actionText, this.actionTextFont, textBrush, actionTextRect, stringFormat);
                }
            }

            int descriptionTextX     = actionTextX;
            int descriptionTextY     = actionTextRect.Bottom + paddingY;
            int descriptionTextWidth = actionTextWidth;

            SizeF descriptionTextSize = g.MeasureString(this.explanationText, this.explanationTextFont,
                                                        descriptionTextWidth, stringFormat);

            Rectangle descriptionTextRect = new Rectangle(descriptionTextX, descriptionTextY,
                                                          descriptionTextWidth, (int)Math.Ceiling(descriptionTextSize.Height));

            if (enableDrawing)
            {
                if (state == PushButtonState.Disabled)
                {
                    ControlPaint.DrawStringDisabled(g, this.explanationText, this.explanationTextFont, this.BackColor, descriptionTextRect, stringFormat);
                }
                else
                {
                    g.DrawString(this.explanationText, this.explanationTextFont, textBrush, descriptionTextRect, stringFormat);
                }
            }

            if (enableDrawing)
            {
                if (drawFocusCues)
                {
                    ControlPaint.DrawFocusRectangle(g, new Rectangle(3, 3, ClientSize.Width - 5, ClientSize.Height - 5));
                }
            }

            if (textBrush != null)
            {
                textBrush.Dispose();
                textBrush = null;
            }

            stringFormat.Dispose();
            stringFormat = null;

            Size layoutSize = new Size(ClientSize.Width, descriptionTextRect.Bottom + marginYBottom);

            return(layoutSize);
        }
        /// <summary>
        /// Draws the day header.
        /// </summary>
        /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
        /// <param name="rect">The <see cref="Rectangle"/> to draw in.</param>
        public override void DrawDayHeader(Graphics g, Rectangle rect)
        {
            // get day width
            int dayWidth = this.monthCal.DaySize.Width;

            if (!CheckParams(g, rect) || dayWidth <= 0)
            {
                return;
            }

            // get abbreviated day names
            List <string> names = new List <string>(DateMethods.GetDayNames(this.monthCal.FormatProvider, this.monthCal.UseShortestDayNames ? 2 : 1));

            // if in RTL mode, reverse order
            if (this.monthCal.UseRTL)
            {
                names.Reverse();
            }

            // get bounds for a single element
            Rectangle dayRect = rect;

            dayRect.Width = dayWidth;

            // draw day names
            using (StringFormat format =
                       new StringFormat(StringFormatFlags.LineLimit | StringFormatFlags.NoWrap)
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            })
            {
                using (SolidBrush brush = new SolidBrush(this.ColorTable.DayHeaderText))
                {
                    names.ForEach(day =>
                    {
                        if (this.monthCal.Enabled)
                        {
                            g.DrawString(day, this.monthCal.DayHeaderFont, brush, dayRect, format);
                        }
                        else
                        {
                            ControlPaint.DrawStringDisabled(
                                g,
                                day,
                                this.monthCal.DayHeaderFont,
                                Color.Transparent,
                                dayRect,
                                format);
                        }

                        dayRect.X += dayWidth;
                    });
                }
            }

            // draw separator line
            using (Pen p = new Pen(GetGrayColor(this.monthCal.Enabled, this.ColorTable.MonthSeparator)))
            {
                g.DrawLine(p, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
            }
        }
예제 #30
0
        protected override void OnPaint(PaintEventArgs e)
        {
            bool hovered = this.RectangleToScreen(this.ClientRectangle).Contains(MousePosition);

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            //content border
            Rectangle rectCont = rectContent;

            rectCont.X      += 1;
            rectCont.Y      += 1;
            rectCont.Width  -= 3;
            rectCont.Height -= 3;
            GraphicsPath pathContentBorder = CreateRoundRectangle(rectCont, Radius.TopLeft, Radius.TopRight, Radius.BottomRight,
                                                                  Radius.BottomLeft);

            //button border
            Rectangle rectButton = rectBtn;

            rectButton.X      += 1;
            rectButton.Y      += 1;
            rectButton.Width  -= 3;
            rectButton.Height -= 3;
            GraphicsPath pathBtnBorder = CreateRoundRectangle(rectButton, 0, Radius.TopRight, Radius.BottomRight, 0);

            //outer border
            Rectangle rectOuter = rectContent;

            rectOuter.Width  -= 1;
            rectOuter.Height -= 1;
            GraphicsPath pathOuterBorder = CreateRoundRectangle(rectOuter, Radius.TopLeft, Radius.TopRight, Radius.BottomRight,
                                                                Radius.BottomLeft);

            //inner border
            Rectangle rectInner = rectContent;

            rectInner.X      += 1;
            rectInner.Y      += 1;
            rectInner.Width  -= 3;
            rectInner.Height -= 3;
            GraphicsPath pathInnerBorder = CreateRoundRectangle(rectInner, Radius.TopLeft, Radius.TopRight, Radius.BottomRight,
                                                                Radius.BottomLeft);

            //brushes and pens
            Color foreColor    = Color.FromArgb(DroppedDown ? 100 : 50, ForeColor);
            Brush brInnerBrush = new LinearGradientBrush(
                new Rectangle(rectInner.X, rectInner.Y, rectInner.Width, rectInner.Height + 1),
                Color.FromArgb((hovered || DroppedDown || Focused) ? 200 : 100, ForeColor),
                Color.Transparent,
                LinearGradientMode.Vertical);
            Brush brBackground;

            if (this.DropDownStyle == ComboBoxStyle.DropDownList)
            {
                brBackground = new LinearGradientBrush(pathInnerBorder.GetBounds(), BackColor, (hovered || Focused)? Color.FromArgb(100, SystemColors.HotTrack) : foreColor, LinearGradientMode.Vertical);
            }
            else
            {
                brBackground = new SolidBrush(BackColor);
            }
            Pen penInnerBorder = new Pen(brInnerBrush, 0);
            LinearGradientBrush brButtonLeft = new LinearGradientBrush(rectBtn, BackColor, ForeColor, LinearGradientMode.Vertical);
            ColorBlend          blend        = new ColorBlend();

            blend.Colors    = new Color[] { Color.Transparent, foreColor, Color.Transparent };
            blend.Positions = new float[] { 0.0f, 0.5f, 1.0f };
            brButtonLeft.InterpolationColors = blend;
            Pen   penLeftButton = new Pen(brButtonLeft, 0);
            Brush brButton      = new LinearGradientBrush(pathBtnBorder.GetBounds(), BackColor, foreColor, LinearGradientMode.Vertical);

            //draw
            e.Graphics.FillPath(brBackground, pathContentBorder);
            if (DropDownStyle != ComboBoxStyle.DropDownList)
            {
                e.Graphics.FillPath(brButton, pathBtnBorder);
            }
            Color outerBorderColor = GetOuterBorderColor();

            if (outerBorderColor.IsSystemColor)
            {
                Pen penOuterBorder = SystemPens.FromSystemColor(outerBorderColor);
                e.Graphics.DrawPath(penOuterBorder, pathOuterBorder);
            }
            else
            {
                using (Pen penOuterBorder = new Pen(outerBorderColor))
                    e.Graphics.DrawPath(penOuterBorder, pathOuterBorder);
            }
            e.Graphics.DrawPath(penInnerBorder, pathInnerBorder);

            e.Graphics.DrawLine(penLeftButton, rectBtn.Left + 1, rectInner.Top + 1, rectBtn.Left + 1, rectInner.Bottom - 1);


            //Glimph
            Rectangle rectGlimph = rectButton;

            rectButton.Width -= 4;
            e.Graphics.TranslateTransform(rectGlimph.Left + rectGlimph.Width / 2.0f, rectGlimph.Top + rectGlimph.Height / 2.0f);
            GraphicsPath path = new GraphicsPath();

            PointF[] points = new PointF[3];
            points[0] = new PointF(-6 / 2.0f, -3 / 2.0f);
            points[1] = new PointF(6 / 2.0f, -3 / 2.0f);
            points[2] = new PointF(0, 6 / 2.0f);
            path.AddLine(points[0], points[1]);
            path.AddLine(points[1], points[2]);
            path.CloseFigure();
            e.Graphics.RotateTransform(0);

            SolidBrush br = new SolidBrush(Enabled ? Color.Gray : Color.Gainsboro);

            e.Graphics.FillPath(br, path);
            e.Graphics.ResetTransform();
            br.Dispose();
            path.Dispose();

            // image
            if (ImageList != null)
            {
                int idx = GetImageKey(SelectedIndex);
                if (idx >= 0)
                {
                    this.ImageList.Draw(e.Graphics, rectTextBounds.Left - this.ImageList.ImageSize.Width - 5, rectContent.Y + 2, idx);
                }
            }

            //text
            if (DropDownStyle == ComboBoxStyle.DropDownList)
            {
                StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);
                sf.Alignment = StringAlignment.Near;

                Rectangle rectText = rectTextBounds;
                rectText.Offset(-3, 0);

                SolidBrush foreBrush = new SolidBrush(ForeColor);
                if (Enabled)
                {
                    e.Graphics.DrawString(Text, this.Font, foreBrush, rectText, sf);
                }
                else
                {
                    ControlPaint.DrawStringDisabled(e.Graphics, Text, Font, BackColor, rectText, sf);
                }
            }

            /*
             * Dim foreBrush As SolidBrush = New SolidBrush(color)
             * If (enabled) Then
             *      g.DrawString(text, font, foreBrush, rect, sf)
             * Else
             *      ControlPaint.DrawStringDisabled(g, text, font, backColor, _
             *               rect, sf)
             * End If
             * foreBrush.Dispose()*/


            pathContentBorder.Dispose();
            pathOuterBorder.Dispose();
            pathInnerBorder.Dispose();
            pathBtnBorder.Dispose();

            penInnerBorder.Dispose();
            penLeftButton.Dispose();

            brBackground.Dispose();
            brInnerBrush.Dispose();
            brButtonLeft.Dispose();
            brButton.Dispose();
        }