示例#1
0
 public override void Paint(Graphics g)
 {
     base.Paint(g);
     if (m_pressed.Value)
     {
         m_drawPressed(Area, g);
     }
     else if (m_hovered.Value)
     {
         m_drawHovered(Area, g);
     }
     else
     {
         m_drawNeutral(Area, g);
     }
     if (m_text != null)
     {
         using (var textRenderer = new NativeTextRenderer(g))
         {
             string text         = m_text();
             Size   textSize     = textRenderer.MeasureString(text, m_font);
             int    offset       = m_pressed.Value ? 1 : 0;
             PointF textLocation = new PointF((Area.Width - textSize.Width) / 2 + offset, (Area.Height - textSize.Height) / 2 + offset);
             textRenderer.DrawString(text, m_font, Color.White, textLocation.Round());
         }
     }
 }
示例#2
0
        private void CustomDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            if (e.Index < 0 || e.Index > Items.Count || !Focused)
            {
                return;
            }

            Graphics g = e.Graphics;

            // Draw the background of the item.
            g.FillRectangle(SkinManager.BackgroundBrush, e.Bounds);

            // Hover
            if (e.State.HasFlag(DrawItemState.Focus)) // Focus == hover
            {
                g.FillRectangle(SkinManager.BackgroundHoverBrush, e.Bounds);
            }

            string Text = "";

            if (!string.IsNullOrWhiteSpace(DisplayMember))
            {
                Text = Items[e.Index].GetType().GetProperty(DisplayMember).GetValue(Items[e.Index], null).ToString();
            }
            else
            {
                Text = Items[e.Index].ToString();
            }

            if (SkinManager.Theme == MaterialSkinManager.Themes.DARK)
            {
                using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
                {
                    NativeText.DrawTransparentText(
                        Text,
                        SkinManager.getFontByType(MaterialSkinManager.fontType.Subtitle1),
                        SkinManager.TextHighEmphasisColor,
                        new Point(e.Bounds.Location.X + SkinManager.FORM_PADDING, e.Bounds.Location.Y),
                        new Size(e.Bounds.Size.Width - SkinManager.FORM_PADDING * 2, e.Bounds.Size.Height),
                        NativeTextRenderer.TextAlignFlags.Left | NativeTextRenderer.TextAlignFlags.Middle);;
                }
            }
            else
            {
                using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
                {
                    NativeText.DrawString(
                        Text,
                        SkinManager.getFontByType(MaterialSkinManager.fontType.Subtitle1),
                        SkinManager.TextHighEmphasisColor,
                        new Rectangle(
                            new Point(e.Bounds.Location.X + SkinManager.FORM_PADDING, e.Bounds.Location.Y),
                            new Size(e.Bounds.Size.Width - SkinManager.FORM_PADDING * 2, e.Bounds.Size.Height)),
                        NativeTextRenderer.TextFormatFlags.SingleLine | NativeTextRenderer.TextFormatFlags.VCenter);
                }
            }
        }