Ejemplo n.º 1
0
        protected override void OnDrawItem(DrawListViewItemEventArgs e)
        {
            //We draw the current line of items (= item with subitems) on a temp bitmap, then draw the bitmap at once. This is to reduce flickering.
            var b = new Bitmap(e.Item.Bounds.Width, e.Item.Bounds.Height);
            var g = Graphics.FromImage(b);

            //always draw default background
            g.FillRectangle(new SolidBrush(MaterialSkinManager.GetApplicationBackgroundColor()), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size));

            if (e.State.HasFlag(ListViewItemStates.Selected))
            {
                //selected background
                g.FillRectangle(MaterialSkinManager.GetFlatButtonPressedBackgroundBrush(), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size));
            }
            else if (e.Bounds.Contains(MouseLocation) && MouseState == MouseState.HOVER)
            {
                //hover background
                g.FillRectangle(MaterialSkinManager.GetFlatButtonHoverBackgroundBrush(), new Rectangle(new Point(e.Bounds.X, 0), e.Bounds.Size));
            }


            //Draw separator
            g.DrawLine(new Pen(MaterialSkinManager.GetDividersColor()), e.Bounds.Left, 0, e.Bounds.Right, 0);

            foreach (ListViewItem.ListViewSubItem subItem in e.Item.SubItems)
            {
                //Draw text
                g.DrawString(subItem.Text, MaterialSkinManager.ROBOTO_MEDIUM_10, MaterialSkinManager.GetPrimaryTextBrush(),
                             new Rectangle(subItem.Bounds.X + ITEM_PADDING, ITEM_PADDING, subItem.Bounds.Width - 2 * ITEM_PADDING, subItem.Bounds.Height - 2 * ITEM_PADDING),
                             getStringFormat());
            }

            e.Graphics.DrawImage((Image)b.Clone(), new Point(0, e.Item.Bounds.Location.Y));
            g.Dispose();
            b.Dispose();
        }
Ejemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;

            g.TextRenderingHint = TextRenderingHint.AntiAlias;

            g.Clear(MaterialSkinManager.GetApplicationBackgroundColor());
            g.FillRectangle(MaterialSkinManager.ColorScheme.DarkPrimaryBrush, statusBarBounds);
            g.FillRectangle(MaterialSkinManager.ColorScheme.PrimaryBrush, actionBarBounds);

            //Draw border
            using (var borderPen = new Pen(MaterialSkinManager.GetDividersColor(), 1))
            {
                g.DrawLine(borderPen, new Point(0, actionBarBounds.Bottom), new Point(0, Height - 2));
                g.DrawLine(borderPen, new Point(Width - 1, actionBarBounds.Bottom), new Point(Width - 1, Height - 2));
                g.DrawLine(borderPen, new Point(0, Height - 1), new Point(Width - 1, Height - 1));
            }

            // Determine whether or not we even should be drawing the buttons.
            bool showMin    = MinimizeBox && ControlBox;
            bool showMax    = MaximizeBox && ControlBox;
            var  hoverBrush = MaterialSkinManager.GetFlatButtonHoverBackgroundBrush();
            var  downBrush  = MaterialSkinManager.GetFlatButtonPressedBackgroundBrush();

            // When MaximizeButton == false, the minimize button will be painted in its place
            if (buttonState == ButtonState.MinOver && showMin)
            {
                g.FillRectangle(hoverBrush, showMax ? minButtonBounds : maxButtonBounds);
            }

            if (buttonState == ButtonState.MinDown && showMin)
            {
                g.FillRectangle(downBrush, showMax ? minButtonBounds : maxButtonBounds);
            }

            if (buttonState == ButtonState.MaxOver && showMax)
            {
                g.FillRectangle(hoverBrush, maxButtonBounds);
            }

            if (buttonState == ButtonState.MaxDown && showMax)
            {
                g.FillRectangle(downBrush, maxButtonBounds);
            }

            if (buttonState == ButtonState.XOver && ControlBox)
            {
                g.FillRectangle(hoverBrush, xButtonBounds);
            }

            if (buttonState == ButtonState.XDown && ControlBox)
            {
                g.FillRectangle(downBrush, xButtonBounds);
            }

            using (var formButtonsPen = new Pen(MaterialSkinManager.ACTION_BAR_TEXT_SECONDARY, 2))
            {
                // Minimize button.
                if (showMin)
                {
                    int x = showMax ? minButtonBounds.X : maxButtonBounds.X;
                    int y = showMax ? minButtonBounds.Y : maxButtonBounds.Y;

                    g.DrawLine(
                        formButtonsPen,
                        x + (int)(minButtonBounds.Width * 0.33),
                        y + (int)(minButtonBounds.Height * 0.66),
                        x + (int)(minButtonBounds.Width * 0.66),
                        y + (int)(minButtonBounds.Height * 0.66)
                        );
                }

                // Maximize button
                if (showMax)
                {
                    g.DrawRectangle(
                        formButtonsPen,
                        maxButtonBounds.X + (int)(maxButtonBounds.Width * 0.33),
                        maxButtonBounds.Y + (int)(maxButtonBounds.Height * 0.36),
                        (int)(maxButtonBounds.Width * 0.39),
                        (int)(maxButtonBounds.Height * 0.31)
                        );
                }

                // Close button
                if (ControlBox)
                {
                    g.DrawLine(
                        formButtonsPen,
                        xButtonBounds.X + (int)(xButtonBounds.Width * 0.33),
                        xButtonBounds.Y + (int)(xButtonBounds.Height * 0.33),
                        xButtonBounds.X + (int)(xButtonBounds.Width * 0.66),
                        xButtonBounds.Y + (int)(xButtonBounds.Height * 0.66)
                        );

                    g.DrawLine(
                        formButtonsPen,
                        xButtonBounds.X + (int)(xButtonBounds.Width * 0.66),
                        xButtonBounds.Y + (int)(xButtonBounds.Height * 0.33),
                        xButtonBounds.X + (int)(xButtonBounds.Width * 0.33),
                        xButtonBounds.Y + (int)(xButtonBounds.Height * 0.66));
                }
            }

            //Form title
            g.DrawString(Text, MaterialSkinManager.ROBOTO_MEDIUM_12, MaterialSkinManager.ColorScheme.TextBrush, new Rectangle(MaterialSkinManager.FORM_PADDING, STATUS_BAR_HEIGHT, Width, ACTION_BAR_HEIGHT), new StringFormat {
                LineAlignment = StringAlignment.Center
            });
            if (!DesignMode && Controls.Count > 0 && !resizing)
            {
                this.DrawChildShadow(g);
            }
        }