Esempio n. 1
0
        private void drawItems(Graphics g)
        {
            var   headerHeight = GetHeaderHeight();
            var   rowHeight    = GetRowHeight();
            var   viewHeight   = GetViewHeight(headerHeight);
            float totWidth     = this.columns.Sum(c => c.Width);

            var t = g.Save();

            g.SetClip(new RectangleF(1, headerHeight + 1, this.Size.Width - 2, viewHeight), System.Drawing.Drawing2D.CombineMode.Intersect);
            g.TranslateTransform(0, -curViewPosition + headerHeight + 1);

            for (int i = 0; i < items.Count; i++)
            {
                ListViewRow item = items[i];

                bool over     = curOverRow == item;
                bool selected = selectedRows.Contains(item);

                Brush     bg;
                Pen       border;
                NinePatch patch = null;

                if (over && selected)
                {
                    bg     = Brushes.LightBlue;
                    border = Pens.LightBlue;
                    patch  = backgroundRowSelectedOver9P;
                }
                else if (over)
                {
                    bg     = Brushes.AliceBlue;
                    border = Pens.LightBlue;
                    patch  = backgroundRowOver9P;
                }
                else if (selected)
                {
                    bg     = Brushes.LightBlue;
                    border = Pens.LightBlue;
                    patch  = backgroundRowSelected9P;
                }
                else
                {
                    bg     = Brushes.Transparent;
                    border = Pens.Transparent;
                    patch  = backgroundRowNormal9P;
                }

                if (patch != null)
                {
                    patch.Paint(g, new RectangleF(1, 0 + rowHeight * i, totWidth - 1, rowHeight));
                }
                else
                {
                    g.FillRectangle(bg, 1, 0 + rowHeight * i, totWidth - 1, rowHeight);
                    g.DrawRectangle(border, 1, 0 + rowHeight * i, totWidth - 1, rowHeight);
                }

                float width_sum = 0;
                for (int j = 0; j < columns.Count; j++)
                {
                    var col = columns[j];

                    var s = g.Save();

                    var content = "";
                    if (j < item.Values.Count)
                    {
                        if (items[i].Values[j] != null)
                        {
                            content = items[i].Values[j].ToString();
                        }
                        else
                        {
                            content = "";
                        }
                    }
                    var strFont  = this.activeRow == item ? this.activeRowFont : this.Font;
                    var strBrush = new SolidBrush(this.activeRow == item ? this.activeRowForeColor : this.ForeColor);
                    var strSize  = g.MeasureString(content, strFont);

                    if (patch != null)
                    {
                        RectangleF contentbox = patch.GetContentBox(new SizeF(col.Width, rowHeight));
                        RectangleF textBox    = new RectangleF(width_sum + contentbox.X, (rowHeight * i) + contentbox.Y, contentbox.Width, contentbox.Height);
                        g.SetClip(textBox, System.Drawing.Drawing2D.CombineMode.Intersect);
                        g.DrawString(content, strFont, strBrush, textBox.X, textBox.Y + (textBox.Height / 2 - strSize.Height / 2 + 1));
                    }
                    else
                    {
                        g.SetClip(new RectangleF(width_sum, (rowHeight * i) + 1, col.Width - 3, rowHeight - 2), System.Drawing.Drawing2D.CombineMode.Intersect);
                        g.DrawString(content, strFont, strBrush, width_sum + 5, (rowHeight * i) + (rowHeight / 2 - strSize.Height / 2 + 1));
                    }

                    g.Restore(s);

                    width_sum += col.Width;
                }

                this.paintedColumnsTotalWidth = width_sum;
            }

            g.Restore(t);
        }
Esempio n. 2
0
        protected override void OnPaint(System.Drawing.Graphics g)
        {
            var contentBox = new RectangleF(0, 0, this.Size.Width, this.Size.Height);

            // Disegno sfondo
            if (backgroundNormal9P != null)
            {
                contentBox = backgroundNormal9P.GetContentBox(this.Size);
                backgroundNormal9P.Paint(g, this.Size);
            }
            else
            {
                drawDefaultBackground(g);
            }


            float cx_pos            = (float)this.value * contentBox.Width / (float)(this.maximum - this.minimum);
            var   indicator_bar_box = new RectangleF(contentBox.X, contentBox.Y, cx_pos, contentBox.Height);

            // Disegno barra indicatore
            if (indicatorBar9P != null)
            {
                indicatorBar9P.Paint(g, indicator_bar_box);
            }

            // Disegno indicatore
            float indicator_width = indicatorNormal9P != null ? indicatorNormal9P.Image.Width - 2 : DEFAULT_INDICATOR_WIDTH;
            var   indicator_box   = new RectangleF(contentBox.X + cx_pos - (indicator_width / 2f), contentBox.Y, indicator_width - 1, contentBox.Height);

            if (pressed)
            {
                if (indicatorPressed9P != null)
                {
                    indicatorPressed9P.Paint(g, indicator_box);
                }
                else
                {
                    drawDefaultIndicator(g, indicator_box);
                }
            }
            else if (over)
            {
                if (indicatorOver9P != null)
                {
                    indicatorOver9P.Paint(g, indicator_box);
                }
                else
                {
                    drawDefaultIndicator(g, indicator_box);
                }
            }
            else
            {
                if (indicatorNormal9P != null)
                {
                    indicatorNormal9P.Paint(g, indicator_box);
                }
                else
                {
                    drawDefaultIndicator(g, indicator_box);
                }
            }

            //g.DrawRectangle(Pens.Red, contentBox.X, contentBox.Y, contentBox.Width, contentBox.Height);
            //g.DrawRectangle(Pens.Blue, indicator_bar_box.X, indicator_bar_box.Y, indicator_bar_box.Width, indicator_bar_box.Height);
            //g.DrawRectangle(Pens.Blue, indicator_box.X, indicator_box.Y, indicator_box.Width-1, indicator_box.Height);
            //g.DrawLine(Pens.Red, contentBox.X + cx_pos, 0, contentBox.X + cx_pos, this.Size.Height);
        }