Exemplo n.º 1
0
 private void ManagedListViewPanel1_DrawSubItem(object sender, ManagedListViewSubItemDrawArgs e)
 {
     if (DrawSubItem != null)
     {
         DrawSubItem(this, e);
     }
 }
Exemplo n.º 2
0
 private void managedListView1_DrawSubItem(object sender, ManagedListViewSubItemDrawArgs e)
 {
 }
Exemplo n.º 3
0
        private void DrawDetailsView(PaintEventArgs pe)
        {
            if (columns == null) return;
            int cX = 0;
            int x = 0;
            int i = 0;
            //get default size of word
            Size CharSize = TextRenderer.MeasureText("TEST", this.Font);
            columnHeight = CharSize.Height + columnh;
            int columnTextOffset = columnh / 2;
            itemHeight = CharSize.Height + itemh;
            int itemTextOffset = itemh / 2;
            int lines = (this.Height / itemHeight) + 2;
            bool resetX = false;
            int offset = VscrollOffset % itemHeight;

            foreach (ManagedListViewColumn column in columns)
            {
                cX += column.Width;

                if (cX >= HscrollOffset)
                {
                    if (items != null)
                    {
                        int lineIndex = VscrollOffset / itemHeight;
                        
                        //draw sub items related to this column
                        for (int j = 0; j < lines; j++)
                        {
                            if (lineIndex < items.Count)
                            {
                                if (resetX)
                                {
                                    resetX = false;
                                    x = 0;
                                }
                                if (x == 0)
                                {
                                    if (items[lineIndex].IsChildItem)
                                    {
                                        x = 15;
                                        resetX = true;
                                    }
                                }
                                //clear
                                if (backgroundThumbnail == null)
                                {
                                    pe.Graphics.FillRectangle(new SolidBrush(base.BackColor),
                                       new Rectangle(x - HscrollOffset + 1, (j * itemHeight) - offset + columnHeight + 1,
                                           column.Width - 1, itemHeight));
                                }
                                if (items[lineIndex].IsSpecialItem)
                                {
                                    pe.Graphics.FillRectangle(new SolidBrush(ItemSpecialColor),
                                    new Rectangle(x - HscrollOffset, (j * itemHeight) - offset + columnHeight + 1,
                                        column.Width - 1, itemHeight));
                                }
                                if (items[lineIndex].Selected)
                                {
                                    pe.Graphics.FillRectangle(new SolidBrush(ItemHighlightColor),
                                      new Rectangle(x - HscrollOffset, (j * itemHeight) - offset + columnHeight + 1,
                                          column.Width - 1, itemHeight));
                                }
                                else
                                {
                                    if (highlightItemAsOver)
                                    {
                                        if (lineIndex == overItemSelectedIndex)
                                        {
                                            if (DrawHighlight)
                                                pe.Graphics.FillRectangle(new SolidBrush(ItemMouseOverColor),
                                                new Rectangle(x - HscrollOffset, (j * itemHeight) - offset + columnHeight + 1,
                                                    column.Width - 1, itemHeight));
                                        }
                                    }
                                }

                                ManagedListViewSubItem subitem = items[lineIndex].GetSubItemByID(column.ID);
                                if (subitem != null)
                                {
                                    Color drawColor = subitem.Color;
                                    Font drawFont = subitem.CustomFontEnabled ? subitem.CustomFont : this.Font;

                                    if (subitem.GetType() == typeof(ManagedListViewRatingSubItem))
                                    {
                                        ((ManagedListViewRatingSubItem)subitem).OnRefreshRating(lineIndex, itemHeight);
                                        Image img = Properties.Resources.noneRating;
                                        if (!((ManagedListViewRatingSubItem)subitem).DrawOverImage)
                                        {
                                            switch (((ManagedListViewRatingSubItem)subitem).Rating)
                                            {
                                                case 1: img = Properties.Resources.star_1; break;
                                                case 2: img = Properties.Resources.star_2; break;
                                                case 3: img = Properties.Resources.star_3; break;
                                                case 4: img = Properties.Resources.star_4; break;
                                                case 5: img = Properties.Resources.star_5; break;
                                            }
                                        }
                                        else
                                        {
                                            switch (((ManagedListViewRatingSubItem)subitem).OverRating)
                                            {
                                                case 1: img = Properties.Resources.star_1; break;
                                                case 2: img = Properties.Resources.star_2; break;
                                                case 3: img = Properties.Resources.star_3; break;
                                                case 4: img = Properties.Resources.star_4; break;
                                                case 5: img = Properties.Resources.star_5; break;
                                            }
                                        }
                                        img = img.GetThumbnailImage(itemHeight * 4, itemHeight - 1, null, IntPtr.Zero);
                                        int imgWidth = itemHeight * 4;
                                        if (imgWidth > column.Width)
                                            imgWidth = column.Width;
                                        pe.Graphics.DrawImageUnscaledAndClipped(img,
                                        new Rectangle(x - HscrollOffset + 2, (j * itemHeight) - offset + columnHeight + 1,
                                        imgWidth, itemHeight - 1));

                                        ((ManagedListViewRatingSubItem)subitem).DrawOverImage = false;
                                    }
                                    else
                                    {
                                        switch (subitem.DrawMode)
                                        {
                                            case ManagedListViewItemDrawMode.Text:
                                                pe.Graphics.DrawString(subitem.Text, drawFont, new SolidBrush(drawColor),
                                                    new Rectangle(x - HscrollOffset + 2,
                                                         (j * itemHeight) - offset + columnHeight + itemTextOffset,
                                                        column.Width, CharSize.Height), _StringFormat);
                                                break;
                                            case ManagedListViewItemDrawMode.Image:
                                                if (subitem.ImageIndex < ImagesList.Images.Count)
                                                {
                                                    pe.Graphics.DrawImage(ImagesList.Images[subitem.ImageIndex],
                                                        new Rectangle(x - HscrollOffset + 2, (j * itemHeight) - offset + columnHeight + 1,
                                                            itemHeight - 1, itemHeight - 1));
                                                }
                                                break;
                                            case ManagedListViewItemDrawMode.TextAndImage:
                                                int plus = 2;
                                                if (subitem.ImageIndex < ImagesList.Images.Count)
                                                {
                                                    pe.Graphics.DrawImage(ImagesList.Images[subitem.ImageIndex],
                                                      new Rectangle(x - HscrollOffset + 2, (j * itemHeight) - offset + columnHeight + 1,
                                                          itemHeight - 1, itemHeight - 1));
                                                    plus += itemHeight;
                                                }
                                                pe.Graphics.DrawString(subitem.Text, drawFont, new SolidBrush(drawColor),
                                                    new Rectangle(x - HscrollOffset + 2 + plus,
                                                         (j * itemHeight) - offset + columnHeight + itemTextOffset,
                                                        column.Width - plus, CharSize.Height), _StringFormat);
                                                break;
                                            case ManagedListViewItemDrawMode.UserDraw:    //Raise the event
                                                if (DrawSubItem != null)
                                                {
                                                    ManagedListViewSubItemDrawArgs args = new ManagedListViewSubItemDrawArgs(column.ID, lineIndex, items[lineIndex]);
                                                    DrawSubItem(this, args);
                                                    int p = 2;
                                                    if (args.ImageToDraw != null)
                                                    {
                                                        pe.Graphics.DrawImage(args.ImageToDraw,
                                                            new Rectangle(x - HscrollOffset + 2, (j * itemHeight) - offset + columnHeight + 1
                                                                , itemHeight - 1, itemHeight - 1));
                                                        p += itemHeight;
                                                    }
                                                    pe.Graphics.DrawString(args.TextToDraw, drawFont, new SolidBrush(drawColor),
                                                    new Rectangle(x - HscrollOffset + 2 + p,
                                                         (j * itemHeight) - offset + columnHeight + itemTextOffset,
                                                        column.Width - p, CharSize.Height), _StringFormat);
                                                }
                                                break;
                                        }
                                    }
                                }
                            }
                            lineIndex++;
                        }
                        if (resetX)
                        {
                            resetX = false;
                            x = 0;
                        } 
                    }
                    //draw the column rectangle, draw the column after the item to hide the offset
                    Color Hcolor = ColumnColor;
                    if (highlightSelectedColumn && selectedColumnIndex == i)
                    {
                        if (!isMouseDown)
                            Hcolor = ColumnHighlightColor;
                        else
                        {
                            if (moveType != ManagedListViewMoveType.ColumnVLine)
                                Hcolor = ColumnClickColor;
                            else
                                Hcolor = ColumnHighlightColor;
                        }
                    }
                    //DRAW COLUMN
                    pe.Graphics.FillRectangle(new LinearGradientBrush(new Point(), new Point(0, columnHeight), Hcolor, Color.White),
                            new Rectangle(x - HscrollOffset + 1, 1, column.Width, columnHeight));
                    //draw the column line
                    pe.Graphics.DrawLine(new Pen(Brushes.LightGray), new Point(cX - HscrollOffset, 1),
                        new Point(cX - HscrollOffset, this.Height - 1));
                    //draw the column text
                    pe.Graphics.DrawString(column.HeaderText, this.Font,
                        new SolidBrush(column.HeaderTextColor), new Rectangle(x - HscrollOffset + 2, columnTextOffset, column.Width,
                            columnHeight), _StringFormat);
                    //Raise the event
                    if (DrawColumn != null)
                        DrawColumn(this, new ManagedListViewColumnDrawArgs(column.ID, pe.Graphics,
                            new Rectangle(x - HscrollOffset, 2, column.Width, columnHeight)));
                    //draw sort triangle
                    switch (column.SortMode)
                    {
                        case ManagedListViewSortMode.AtoZ:
                            pe.Graphics.DrawImage(Properties.Resources.SortAlpha.ToBitmap(),
                                new Rectangle(x - HscrollOffset + column.Width - 14, 2, 12, 16));
                            break;
                        case ManagedListViewSortMode.ZtoA:
                            pe.Graphics.DrawImage(Properties.Resources.SortZ.ToBitmap(),
                                new Rectangle(x - HscrollOffset + column.Width - 14, 2, 12, 16));
                            break;
                    }
                }
                x += column.Width;
                i++;
                if (x - HscrollOffset > this.Width)
                    break;
            }
            if (columns.Count > 0)
                pe.Graphics.DrawLine(new Pen(new SolidBrush(Color.Gray)), new Point(0, columnHeight), new Point(this.Width, columnHeight));
            if (isMovingColumn)
            {
                pe.Graphics.FillRectangle(new LinearGradientBrush(new Point(), new Point(0, columnHeight), Color.White, Color.Silver),
                           new Rectangle(CurrentMousePosition.X, 1, columns[selectedColumnIndex].Width, columnHeight));
                //draw the column line
                pe.Graphics.DrawLine(new Pen(Brushes.LightGray), new Point(cX - HscrollOffset, 1),
                    new Point(cX - HscrollOffset, this.Height - 1));
                //draw the column text
                pe.Graphics.DrawString(columns[selectedColumnIndex].HeaderText, this.Font,
                    new SolidBrush(columns[selectedColumnIndex].HeaderTextColor), new Rectangle(CurrentMousePosition.X, 2,
                        columns[selectedColumnIndex].Width, columnHeight), _StringFormat);
            }
        }
Exemplo n.º 4
0
 private void ManagedListViewPanel1_DrawSubItem(object sender, ManagedListViewSubItemDrawArgs e)
 {
     if (DrawSubItem != null)
         DrawSubItem(this, e);
 }