Inheritance: PaintEventArgs
        public override void OnPaint(PaintItemEventArgs e)
        {
            if (ColumnWidth != null && ColumnWidth.Length != MenuTextByColumns.Length)
                throw new Exception("ColumnWidth.Length != MenuTextByColumns.Length");

            int[] columnWidth = ColumnWidth;
            if(columnWidth == null)
            {
                columnWidth = new int[MenuTextByColumns.Length];
                float step = e.TextRect.Width/MenuTextByColumns.Length;
                for (int i = 0; i < MenuTextByColumns.Length; i++)
                    columnWidth[i] = (int)step;
            }

            //draw columns
            Pen pen = Pens.Silver;
            Brush brush = Brushes.Black;
            float x = e.TextRect.X;
            e.StringFormat.FormatFlags = e.StringFormat.FormatFlags | StringFormatFlags.NoWrap;

            for (int i=0;i<MenuTextByColumns.Length;i++)
            {
                var width = columnWidth[i];
                var rect = new RectangleF(x, e.TextRect.Top, width, e.TextRect.Height);
                e.Graphics.DrawLine(pen, new PointF(x, e.TextRect.Top), new PointF(x, e.TextRect.Bottom));
                e.Graphics.DrawString(MenuTextByColumns[i], e.Font, brush, rect, e.StringFormat);
                x += width;
            }
        }
 public virtual void OnPaint(PaintItemEventArgs e)
 {
     e.Graphics.DrawString(ToString(), e.Font, Brushes.Black, e.TextRect, e.StringFormat);
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            bool rtl = RightToLeft == RightToLeft.Yes;
            AdjustScroll();
            int startI = VerticalScroll.Value/ItemHeight - 1;
            int finishI = (VerticalScroll.Value + ClientSize.Height)/ItemHeight + 1;
            startI = Math.Max(startI, 0);
            finishI = Math.Min(finishI, VisibleItems.Count);
            int y = 0;

            for (int i = startI; i < finishI; i++)
            {
                y = i*ItemHeight - VerticalScroll.Value;

                if (ImageList != null && VisibleItems[i].ImageIndex >= 0)
                    if (rtl)
                        e.Graphics.DrawImage(ImageList.Images[VisibleItems[i].ImageIndex], Width - 1 - LeftPadding, y);
                    else
                        e.Graphics.DrawImage(ImageList.Images[VisibleItems[i].ImageIndex], 1, y);

                var textRect = new Rectangle(LeftPadding, y, ClientSize.Width - 1 - LeftPadding, ItemHeight - 1);
                if (rtl)
                    textRect = new Rectangle(1, y, ClientSize.Width - 1 - LeftPadding, ItemHeight - 1);

                if (i == SelectedItemIndex)
                {
                    Brush selectedBrush = new LinearGradientBrush(new Point(0, y - 3), new Point(0, y + ItemHeight),
                                                                  Colors.SelectedBackColor2, Colors.SelectedBackColor);
                    e.Graphics.FillRectangle(selectedBrush, textRect);
                    using(var pen = new Pen(Colors.SelectedBackColor2))
                        e.Graphics.DrawRectangle(pen, textRect);
                }

                if (i == HighlightedItemIndex)
                using (var pen = new Pen(Colors.HighlightingColor))
                    e.Graphics.DrawRectangle(pen, textRect);

                var sf = new StringFormat();
                if (rtl)
                    sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;

                var args = new PaintItemEventArgs(e.Graphics, e.ClipRectangle)
                               {
                                   Font = Font,
                                   TextRect = new RectangleF(textRect.Location, textRect.Size),
                                   StringFormat = sf,
                                   IsSelected = i == SelectedItemIndex,
                                   IsHovered = i == HighlightedItemIndex,
                                   Colors = Colors
                               };
                //call drawing
                VisibleItems[i].OnPaint(args);
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            bool rtl = RightToLeft == RightToLeft.Yes;

            AdjustScroll();
            int startI  = VerticalScroll.Value / ItemHeight - 1;
            int finishI = (VerticalScroll.Value + ClientSize.Height) / ItemHeight + 1;

            startI  = Math.Max(startI, 0);
            finishI = Math.Min(finishI, VisibleItems.Count);
            int y = 0;

            for (int i = startI; i < finishI; i++)
            {
                y = i * ItemHeight - VerticalScroll.Value;

                if (ImageList != null && VisibleItems[i].ImageIndex >= 0)
                {
                    if (rtl)
                    {
                        e.Graphics.DrawImage(ImageList.Images[VisibleItems[i].ImageIndex], Width - 1 - LeftPadding, y);
                    }
                    else
                    {
                        e.Graphics.DrawImage(ImageList.Images[VisibleItems[i].ImageIndex], 1, y);
                    }
                }

                var textRect = new Rectangle(LeftPadding, y, ClientSize.Width - 1 - LeftPadding, ItemHeight - 1);
                if (rtl)
                {
                    textRect = new Rectangle(1, y, ClientSize.Width - 1 - LeftPadding, ItemHeight - 1);
                }

                if (i == SelectedItemIndex)
                {
                    Brush selectedBrush = new LinearGradientBrush(new Point(0, y - 3), new Point(0, y + ItemHeight),
                                                                  Colors.SelectedBackColor2, Colors.SelectedBackColor);
                    e.Graphics.FillRectangle(selectedBrush, textRect);
                    using (var pen = new Pen(Colors.SelectedBackColor2))
                        e.Graphics.DrawRectangle(pen, textRect);
                }

                if (i == HighlightedItemIndex)
                {
                    using (var pen = new Pen(Colors.HighlightingColor))
                        e.Graphics.DrawRectangle(pen, textRect);
                }

                var sf = new StringFormat();
                if (rtl)
                {
                    sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
                }

                var args = new PaintItemEventArgs(e.Graphics, e.ClipRectangle)
                {
                    Font         = Font,
                    TextRect     = new RectangleF(textRect.Location, textRect.Size),
                    StringFormat = sf,
                    IsSelected   = i == SelectedItemIndex,
                    IsHovered    = i == HighlightedItemIndex,
                    Colors       = Colors
                };
                //call drawing
                VisibleItems[i].OnPaint(args);
            }
        }
Exemple #5
0
 public virtual void OnPaint(PaintItemEventArgs e)
 {
     using(var brush = new SolidBrush(e.IsSelected ? e.Colors.SelectedForeColor : e.Colors.ForeColor))
         e.Graphics.DrawString(ToString(), e.Font, brush, e.TextRect, e.StringFormat);
 }
Exemple #6
0
 public virtual void OnPaint(PaintItemEventArgs e)
 {
     using (var brush = new SolidBrush(e.IsSelected ? e.Colors.SelectedForeColor : e.Colors.ForeColor))
         e.Graphics.DrawString(ToString(), e.Font, brush, e.TextRect, e.StringFormat);
 }
Exemple #7
0
 public virtual void OnPaint(PaintItemEventArgs e)
 {
     e.Graphics.DrawString(ToString(), e.Font, Brushes.Black, e.TextRect, e.StringFormat);
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            bool rtl = RightToLeft == RightToLeft.Yes;

            AdjustScroll();
            int startI  = VerticalScroll.Value / ItemHeight - 1;
            int finishI = (VerticalScroll.Value + ClientSize.Height) / ItemHeight + 1;
            int y       = 0;

            var sf = new StringFormat();

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

            if (HasColumn && VerticalScroll.Value == 0)
            {
                var textRect = new Rectangle(LeftPadding, y, ClientSize.Width - 1 - LeftPadding, ItemHeight - 1);
                if (rtl)
                {
                    textRect = new Rectangle(1, y, ClientSize.Width - 1 - LeftPadding, ItemHeight - 1);
                }

                int[] columnWidth = ColumnsWidth;
                if (columnWidth == null)
                {
                    columnWidth = new int[ColumnsTitle.Length];
                    float step = textRect.Width / ColumnsTitle.Length;
                    for (int i = 0; i < ColumnsTitle.Length; i++)
                    {
                        columnWidth[i] = (int)step;
                    }
                }

                float x = textRect.X;
                sf.Alignment = StringAlignment.Center;
                for (int i = 0; i < ColumnsTitle.Length; i++)
                {
                    using (var brush = new SolidBrush(Colors.ForeColor))
                    {
                        var width = columnWidth[i];
                        var rect  = new RectangleF(x, textRect.Top, width, textRect.Height);
                        e.Graphics.DrawLine(Pens.Silver, new PointF(x, textRect.Top), new PointF(x, textRect.Bottom));
                        e.Graphics.DrawString(ColumnsTitle[i], Font, brush, rect, sf);
                        x += width;
                    }
                }
                if (rtl)
                {
                    sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
                }
                else
                {
                    sf = new StringFormat();
                }
            }

            startI  = Math.Max(startI, 0);
            finishI = Math.Min(finishI, VisibleItems.Count);

            for (int i = startI; i < finishI; i++)
            {
                if (HasColumn)
                {
                    y = (i * ItemHeight - VerticalScroll.Value) + ItemHeight;
                }
                else
                {
                    y = i * ItemHeight - VerticalScroll.Value;
                }

                if (ImageList != null && VisibleItems[i].ImageIndex >= 0)
                {
                    if (rtl)
                    {
                        e.Graphics.DrawImage(ImageList.Images[VisibleItems[i].ImageIndex], Width - 1 - LeftPadding, y);
                    }
                    else
                    {
                        e.Graphics.DrawImage(ImageList.Images[VisibleItems[i].ImageIndex], 1, y);
                    }
                }

                var textRect = new Rectangle(LeftPadding, y, ClientSize.Width - 1 - LeftPadding, ItemHeight - 1);
                if (rtl)
                {
                    textRect = new Rectangle(1, y, ClientSize.Width - 1 - LeftPadding, ItemHeight - 1);
                }

                if (i == SelectedItemIndex)
                {
                    Brush selectedBrush = new LinearGradientBrush(new Point(0, y - 3), new Point(0, y + ItemHeight),
                                                                  Colors.SelectedBackColor2, Colors.SelectedBackColor);
                    e.Graphics.FillRectangle(selectedBrush, textRect);
                    using (var pen = new Pen(Colors.SelectedBackColor2))
                        e.Graphics.DrawRectangle(pen, textRect);
                }

                if (i == HighlightedItemIndex)
                {
                    using (var pen = new Pen(Colors.HighlightingColor))
                        e.Graphics.DrawRectangle(pen, textRect);
                }

                var args = new PaintItemEventArgs(e.Graphics, e.ClipRectangle)
                {
                    Font         = Font,
                    TextRect     = new RectangleF(textRect.Location, textRect.Size),
                    StringFormat = sf,
                    IsSelected   = i == SelectedItemIndex,
                    IsHovered    = i == HighlightedItemIndex,
                    Colors       = Colors
                };
                //call drawing
                VisibleItems[i].OnPaint(args);
            }
        }