Example #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle paddedClient = GeometryHelper.ApplyPadding(ContentRectangle, Padding);

            paddedClient.Offset(ScrollPosition);

            if (IsGrouped)
            {
                for (int i = 0; i < Groups.Count; ++i)
                {
                    // TODO: draw header
                    // TODO: draw items
                }
                throw new NotSupportedException("Grouping is not yet supported");
            }
            else
            {
                for (int i = 0; i < Items.Count; ++i)
                {
                    DrawItem(Items[i], e.Graphics, GetItemBounds(i));
                }
            }

            base.OnPaint(e);
        }
Example #2
0
        protected virtual void DrawAndMeasureText(Graphics g)
        {
            Rectangle       textRect = GeometryHelper.ApplyPadding(ClientRectangle, Padding);
            TextFormatFlags flags    =
                TextFormatFlags.Left
                | TextFormatFlags.VerticalCenter
                | TextFormatFlags.SingleLine
                | TextFormatFlags.TextBoxControl
                | TextFormatFlags.NoPadding;

            charPositions    = new int[Text.Length + 1];
            charPositions[0] = Padding.Left;

            int currentTotalWidth = Padding.Left;

            for (int i = 0; i < Text.Length; ++i)
            {
                int charWidth = TextRenderer.MeasureText(g, Text[i].ToString(), Font, textRect.Size, flags).Width;

                bool isSelected = (SelectionStart <= i && i < SelectionStart + SelectionLength);
                if (isSelected)
                {
                    using (Brush brush = new SolidBrush(SelectionBackColor))
                        g.FillRectangle(brush, new Rectangle(textRect.Left, textRect.Top, charWidth, textRect.Height));
                }

                TextRenderer.DrawText(g, Text[i].ToString(), Font, textRect, isSelected ? SelectionForeColor : ForeColor, flags);

                charPositions[i + 1] = currentTotalWidth + charWidth;
                currentTotalWidth   += charWidth;
                textRect             = new Rectangle(textRect.Left + charWidth, textRect.Top, textRect.Width - charWidth, textRect.Height);
            }
        }
Example #3
0
        protected virtual Rectangle GetItemBounds(int index)
        {
            Rectangle paddedClient = GeometryHelper.ApplyPadding(ContentRectangle, Padding);

            paddedClient.Offset(ScrollPosition);

            return(new Rectangle(
                       paddedClient.Left,
                       paddedClient.Top + index * ItemHeight,
                       paddedClient.Width,
                       ItemHeight
                       ));
        }
Example #4
0
        protected virtual RectangleF GetButtonRectangle()
        {
            int        size = Math.Min(ClientRectangle.Width, ClientRectangle.Height) - 2 * BorderWidth;
            RectangleF rect = new RectangleF(
                (ClientRectangle.Width - size) / 2f,
                (ClientRectangle.Height - size) / 2f,
                size,
                size
                );

            if (IsPressed)
            {
                rect = GeometryHelper.ApplyPadding(rect, PressExpansion);
            }
            return(rect);
        }
Example #5
0
        protected virtual void OnSelectedItemChanged(EventArgs e)
        {
            if (SelectedItem != null)
            {
                ScrollIntoView(GeometryHelper.ApplyPadding(GetItemBounds(SelectedItem), new Padding(-ItemBorderWidth)));
                InvokeItem(SelectedItem, InvocationMode.Select);
            }
            Invalidate();

            EventHandler handler = SelectedItemChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Example #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            using (Pen borderPen = new Pen(BorderColor, BorderWidth))
                e.Graphics.DrawRectangle(borderPen, GeometryHelper.ApplyPadding(ClientRectangle, new Padding(BorderWidth / 2)));

            DrawAndMeasureText(e.Graphics);

            if (caretVisible)
            {
                DrawCaret(e.Graphics);
            }

            if (!Enabled)
            {
                PaintHelper.DrawDisabledFilter(e.Graphics, this);
            }
        }
Example #7
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = GeometryHelper.ApplyPadding(ClientRectangle, Padding);

            if (IsPressed)
            {
                rect = GeometryHelper.ApplyPadding(rect, PressExpansion);
            }

            StringFormat format = new StringFormat()
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            using (Pen borderPen = new Pen(IsPressed ? PressedBorderColor : BorderColor, BorderWidth))
                e.Graphics.DrawRectangle(borderPen, rect);

            using (Brush fgBrush = new SolidBrush(IsPressed ? PressedForeColor : ForeColor))
                e.Graphics.DrawString(Text, Font, fgBrush, rect, format);

            base.OnPaint(e);
        }
Example #8
0
 protected override void OnPaintBackground(PaintEventArgs e)
 {
     base.OnPaintBackground(e);
     using (Brush brush = new SolidBrush(IsPressed ? PressedBackColor : BackColor))
         e.Graphics.FillRectangle(brush, IsPressed ? GeometryHelper.ApplyPadding(ClientRectangle, PressExpansion) : ClientRectangle);
 }
Example #9
0
        protected virtual void DrawItem(Item item, Graphics g, Rectangle bounds)
        {
            bool isSelected = (item == SelectedItem);

            if (!isSelected)
            {
                bounds = GeometryHelper.ApplyPadding(bounds, SelectionExpansion);
            }

            using (Brush bgBrush = new SolidBrush(isSelected ? SelectedItemBackColor : BackColor))
                g.FillRectangle(bgBrush, bounds);
            using (Pen borderPen = new Pen(isSelected ? SelectedItemBorderColor : ItemBorderColor, ItemBorderWidth))
                g.DrawRectangle(borderPen, bounds);

            const int margin = 5;

            bounds = GeometryHelper.ApplyPadding(bounds, new Padding(margin));

            StringFormat format = new StringFormat()
            {
                Alignment     = StringAlignment.Near,
                LineAlignment = StringAlignment.Center
            };

            int xOffset = 0;
            int yOffset = 0;

            if (ShowImages)
            {
                Size imageSize = new Size(bounds.Height, bounds.Height);
                if (item.Image != null)
                {
                    g.DrawImage(item.Image, new Rectangle(bounds.Location, imageSize));
                }
                xOffset += imageSize.Width + margin;
            }

            if (ShowTitles)
            {
                float      height   = ShowDetails ? 0.25f * bounds.Height : bounds.Height;
                RectangleF textRect = new RectangleF(bounds.Left + xOffset, bounds.Top + yOffset, bounds.Width - xOffset, height);

                using (Brush brush = new SolidBrush(ForeColor))
                    g.DrawString(item.Title, TitleFont, brush, textRect, format);

                yOffset += (int)height + margin;
            }

            if (ShowDetails)
            {
                RectangleF textRect = new RectangleF(
                    bounds.Left + xOffset,
                    bounds.Top + yOffset,
                    bounds.Width - xOffset,
                    bounds.Height - yOffset
                    );
                format.LineAlignment = StringAlignment.Near;
                using (Brush brush = new SolidBrush(ForeColor))
                    g.DrawString(item.Details, Font, brush, textRect, format);
            }
        }