Exemplo n.º 1
0
        public void DrawText_NullGraphics_ThrowsArgumentNullException()
        {
            var e = new DrawListViewSubItemEventArgs(null, new Rectangle(1, 2, 3, 4), new ListViewItem(), new ListViewItem.ListViewSubItem(), 0, 0, new ColumnHeader(), ListViewItemStates.Checked);

            Assert.Throws <ArgumentNullException>("dc", () => e.DrawText());
            Assert.Throws <ArgumentNullException>("dc", () => e.DrawText(TextFormatFlags.Left));
        }
Exemplo n.º 2
0
 public void DrawText_NullItemNonMinusOneItemIndex_Nop(int itemIndex)
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var e = new DrawListViewSubItemEventArgs(graphics, new Rectangle(1, 2, 3, 4), null, new ListViewItem.ListViewSubItem(), itemIndex, 0, new ColumnHeader(), ListViewItemStates.Checked);
             e.DrawText();
             e.DrawText(TextFormatFlags.Left);
         }
 }
Exemplo n.º 3
0
 public void DrawText_NullSubItemNonMinusOneItemIndex_ThrowsNullReferenceException(int itemIndex)
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var e = new DrawListViewSubItemEventArgs(graphics, new Rectangle(1, 2, 3, 4), new ListViewItem(), null, itemIndex, 0, new ColumnHeader(), ListViewItemStates.Checked);
             Assert.Throws <NullReferenceException>(() => e.DrawText());
             Assert.Throws <NullReferenceException>(() => e.DrawText(TextFormatFlags.Left));
         }
 }
Exemplo n.º 4
0
 public void DrawText_NullHeading_ThrowsNullReferenceException()
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var e = new DrawListViewSubItemEventArgs(graphics, new Rectangle(1, 2, 3, 4), new ListViewItem(), new ListViewItem.ListViewSubItem(), 0, 0, null, ListViewItemStates.Checked);
             Assert.Throws <NullReferenceException>(() => e.DrawText());
             e.DrawText(TextFormatFlags.Left);
         }
 }
Exemplo n.º 5
0
        //TODO: [DEPRICATED] Finish implementing DrawSubItem Event Handler
        private void OnQueryResultsListView_DrawItem(object sender, DrawListViewSubItemEventArgs e)
        {
            using (StringFormat sf = new StringFormat())
            {
                TextFormatFlags flags = TextFormatFlags.Left;
                //e.DrawBackground();
                //e.DrawFocusRectangle();

                switch (e.Header.TextAlign)
                {
                case HorizontalAlignment.Center:
                    sf.Alignment = StringAlignment.Center;
                    flags        = TextFormatFlags.HorizontalCenter;
                    break;

                case HorizontalAlignment.Right:
                    sf.Alignment = StringAlignment.Far;
                    flags        = TextFormatFlags.Right;
                    break;
                }

                if (!string.IsNullOrEmpty(e.Header.ToString()) && e.Header.Text.ToString() == "File Path")
                {
                    string   line      = queryResultsListView.Items[e.ColumnIndex].Text.ToString();
                    string[] lineParts = line.Split(' ');

                    //Microsoft Sans Serif, 7.8pt
                    e.Graphics.DrawString(lineParts[0], new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Black), e.Bounds);
                    e.Graphics.DrawString(lineParts[1], new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Red), e.Bounds);
                    return;
                }

                e.DrawText(flags);
            }
        }
Exemplo n.º 6
0
        private void stack_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            e.DrawBackground();
            if (e.Item.Selected)
            {
                e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds);
            }

            e.DrawText();

            if (e.ColumnIndex == 0)
            {
                if (e.Item.Tag != null)
                {
                    var obj = (DbgThreadObject)e.Item.Tag;
                    if (obj.IsActive)
                    {
                        e.Graphics.DrawImage(Resources.Resources.step, new Point(e.Bounds.X + 2, e.Bounds.Y + 2));
                    }
                }
            }
            else
            {
                SizeF size          = e.Graphics.MeasureString(e.SubItem.Text, threadsList.Font);
                int   requiredWidth = Math.Max(30, (int)size.Width + 20);
                if (threadsList.Columns[e.ColumnIndex].Width < requiredWidth)
                {
                    threadsList.Columns[e.ColumnIndex].Width = requiredWidth + 5;
                }
            }
        }
        private void nodeListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            if (e.ColumnIndex > 0)
            {
                Rectangle bounds = e.SubItem.Bounds;

                if (e.Item.Selected)
                {
                    e.Graphics.FillRectangle(HL_BRUSH, bounds);
                    e.SubItem.ForeColor = SystemColors.HighlightText;
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(e.Item.BackColor), bounds);
                    e.SubItem.ForeColor = e.Item.ForeColor;
                }

                e.DrawText(TextFormatFlags.VerticalCenter);
                e.Graphics.DrawLine(LINE_PEN, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
            }
            else
            {
                e.DrawDefault = true;
            }
        }
Exemplo n.º 8
0
        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
        {
            if (e.SubItem.Text.EndsWith("%", StringComparison.Ordinal))
            {
                float percent;

                if (Single.TryParse(e.SubItem.Text.Remove(e.SubItem.Text.Length - 1), out percent))
                {
                    var rc = new NativeMethods.RECT();
                    rc.Left   = e.Bounds.X + (GridLines ? 2 : 1);
                    rc.Top    = e.Bounds.Y + (GridLines ? 1 : 2);
                    rc.Right  = rc.Left + (int)((e.Bounds.Width - (GridLines ? 4 : 2)) * percent / 100);
                    rc.Bottom = e.Bounds.Bottom - 2;

                    e.DrawText(TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                    NativeMethods.InvertRect(e.Graphics.GetHdc(), ref rc);
                    e.Graphics.ReleaseHdc();
                }
                else
                {
                    e.DrawDefault = true;
                }
            }
            else
            {
                e.DrawDefault = true;
            }

            base.OnDrawSubItem(e);
        }
 public void DrawSubItem(DrawListViewSubItemEventArgs e)
 {
     if (e.Item.Selected)
     {
         e.Graphics.FillRectangle(new SolidBrush(AutomixColorTable.SecondColor), e.Bounds);
     }
     e.DrawText(TextFormatFlags.TextBoxControl);
 }
Exemplo n.º 10
0
        protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
        {
            base.OnDrawSubItem(e);

            if (View != View.LargeIcon)
            {
                return;
            }


            if (e.ItemIndex == -1)
            {
                return;
            }

            Rectangle          bounds    = e.Bounds;
            ListViewItemStates itemState = e.ItemState;
            Graphics           g         = e.Graphics;
            TextFormatFlags    flags     = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter;



            if ((itemState & ListViewItemStates.Selected) == ListViewItemStates.Selected)
            {
            }
            else
            {
                Rectangle imageRect = new Rectangle(bounds.X + 4, bounds.Y + 2, bounds.Height - 4, bounds.Height - 4);
                Image     image     = e.Item.ImageIndex == -1 ? null : e.Item.ImageList.Images[e.Item.ImageIndex];

                if (image == null)
                {
                    e.DrawText(flags);
                    return;
                }
                g.DrawImage(image, imageRect);
                Rectangle textRect = new Rectangle(imageRect.Right + 3, bounds.Y, bounds.Width - imageRect.Right - 3, bounds.Height);

                TextRenderer.DrawText(g, e.Item.Text, e.Item.Font, textRect, e.Item.ForeColor, flags);

                return;
            }

            e.DrawText(flags);
        }
Exemplo n.º 11
0
 private void blockIDListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
 {
     if ((e.ItemState & ListViewItemStates.Selected) != 0)
     {
         e.DrawFocusRectangle(e.Bounds);
     }
     //e.DrawBackground();
     e.DrawText();
 }
Exemplo n.º 12
0
 public void DrawText_HasGraphicsWithFlags_Success(int itemIndex)
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var e = new DrawListViewSubItemEventArgs(graphics, new Rectangle(1, 2, 3, 4), new ListViewItem(), new ListViewItem.ListViewSubItem(), itemIndex, 0, new ColumnHeader(), ListViewItemStates.Checked);
             e.DrawText(TextFormatFlags.Bottom);
         }
 }
Exemplo n.º 13
0
        private void listView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            Brush brush;
            Color backColor;
            Color foreColor;

            if (e.Item.Selected)
            {
                if (listView.Focused)
                {
                    brush     = SystemBrushes.Highlight;
                    backColor = SystemColors.Highlight;
                    foreColor = SystemColors.HighlightText;
                }
                else
                {
                    // We use the same colors here as TreeViewMS does for
                    // drawing unfocused selected rows.
                    brush     = Brushes.LightGray;
                    backColor = Color.LightGray;
                    foreColor = SystemColors.WindowText;
                }
            }
            else
            {
                brush     = SystemBrushes.Window;
                backColor = SystemColors.Window;
                foreColor = SystemColors.WindowText;
            }
            if (e.ColumnIndex == 0)
            {
                // Erase the entire background when drawing the first sub-item
                e.Graphics.FillRectangle(brush, e.Item.Bounds);
            }
            if (e.ColumnIndex == colHdrDisplayText.Index)
            {
                var findResult         = (FindResult)e.Item.Tag;
                var textRendererHelper = new TextRendererHelper
                {
                    ForeColor     = foreColor,
                    BackColor     = backColor,
                    Font          = e.Item.Font,
                    HighlightFont = new Font(e.Item.Font, FontStyle.Bold),
                };
                textRendererHelper.DrawHighlightedText(e.Graphics, e.SubItem.Bounds, findResult.FindMatch);
            }
            else
            {
                e.SubItem.ForeColor = foreColor;
                e.DrawText();
            }
            if (e.ColumnIndex == 0)
            {
                e.DrawFocusRectangle(e.Bounds);
            }
        }
Exemplo n.º 14
0
        private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            switch (e.ColumnIndex)
            {
            case 0:
            {
                Point _point = new Point(
                    e.Bounds.Location.X + 4,
                    e.Bounds.Location.Y + ((e.Bounds.Height - 12) / 2));

                if (e.Item.Checked)
                {
                    CheckBoxRenderer.DrawCheckBox(
                        e.Graphics,
                        _point,
                        System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal);
                }
                else
                {
                    CheckBoxRenderer.DrawCheckBox(
                        e.Graphics,
                        _point,
                        System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
                }
            }
            break;

            case 1:
            {
                Rectangle _rectangle = new Rectangle(
                    e.Bounds.Location.X,
                    e.Bounds.Location.Y + 1 + ((e.Bounds.Height - 12) / 2),
                    e.Bounds.Width,
                    11);

                e.Graphics.FillRectangle(new SolidBrush(e.SubItem.BackColor), _rectangle);
            }
            break;

            case 2:
            {
                if (this.listView1.SelectedItems.Contains(e.Item))
                {
                    e.SubItem.ForeColor = SystemColors.HighlightText;
                }
                else
                {
                    e.SubItem.ForeColor = SystemColors.MenuText;
                }

                e.DrawText(TextFormatFlags.Default);
            }
            break;
            }
        }
Exemplo n.º 15
0
        // Draws subitem text and applies content-based formatting.
        private void listView2_DrawSubItem(object sender,
                                           DrawListViewSubItemEventArgs e)
        {
            TextFormatFlags flags = TextFormatFlags.Left
                                    | TextFormatFlags.NoPadding
                                    | TextFormatFlags.Default
            ;

            using (StringFormat sf = new StringFormat())
            {
                // Store the column text alignment, letting it default
                // to Left if it has not been set to Center or Right.
                switch (e.Header.TextAlign)
                {
                case HorizontalAlignment.Center:
                    sf.Alignment = StringAlignment.Center;
                    flags        = TextFormatFlags.HorizontalCenter;
                    break;

                case HorizontalAlignment.Right:
                    sf.Alignment = StringAlignment.Far;
                    flags        = TextFormatFlags.Right;
                    break;
                }

                // Draw the text and background for a subitem with a
                // negative value.
                //double subItemValue;
                if (e.ColumnIndex == 0
                    //> 0 && Double.TryParse(
                    //e.SubItem.Text, NumberStyles.Currency,
                    //NumberFormatInfo.CurrentInfo, out subItemValue) &&
                    //subItemValue < 0
                    )
                {
                    // Unless the item is selected, draw the standard
                    // background to make it stand out from the gradient.
                    if ((e.ItemState & ListViewItemStates.Selected) == 0)
                    {
                        e.DrawBackground();
                    }

                    // Draw the subitem text in red to highlight it.
                    e.Graphics.DrawString(e.SubItem.Text,
                                          listViewCurrentStagedContainers.Font, Brushes.Red, e.Bounds, sf);

                    return;
                }

                // Draw normal text for a subitem with a nonnegative
                // or nonnumerical value.
                e.DrawText(flags);
            }
        }
Exemplo n.º 16
0
 public void DrawText_HasGraphicsWithoutFlags_Success(int itemIndex, HorizontalAlignment textAlign)
 {
     using (var image = new Bitmap(10, 10))
         using (Graphics graphics = Graphics.FromImage(image))
         {
             var header = new ColumnHeader {
                 TextAlign = textAlign
             };
             var e = new DrawListViewSubItemEventArgs(graphics, new Rectangle(1, 2, 3, 4), new ListViewItem(), new ListViewItem.ListViewSubItem(), itemIndex, 0, header, ListViewItemStates.Checked);
             e.DrawText();
         }
 }
Exemplo n.º 17
0
        private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            TextFormatFlags flags = TextFormatFlags.Left;

            // Align text on the right for the subitems after row 11 in the
            // first column
            if (e.ColumnIndex == 0)
            {
                flags = TextFormatFlags.Right;
            }
            e.Graphics.DrawImage(imageList1.Images[0], 0, 0);
            e.DrawText(flags);
        }
Exemplo n.º 18
0
 private void lvwCreateUser_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
 {
     if (e.Item.Selected)
     {
         e.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), e.Bounds);
         e.Graphics.DrawString(e.SubItem.Text, new Font("Tahoma", 8), new SolidBrush(Color.Black), e.Bounds);
     }
     else
     {
         e.DrawBackground();
         e.DrawText();
     }
 }
Exemplo n.º 19
0
 private void listview_Entering_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
 {
     if (this.listview_Entering.SelectedIndices.Contains(e.ItemIndex))
     {
         e.SubItem.BackColor = System.Drawing.SystemColors.MenuHighlight;
     }
     else
     {
         e.SubItem.BackColor = Color.White;
     }
     e.DrawBackground();
     e.DrawText();
 }
Exemplo n.º 20
0
        private void listView_stock_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            if (this.listView_stock.SelectedIndices.Contains(e.ItemIndex))

            {
                e.SubItem.BackColor = Color.PeachPuff;
            }
            else
            {
                e.SubItem.BackColor = Color.White;
            }
            e.DrawBackground();
            e.DrawText();
        }
Exemplo n.º 21
0
 private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
 {
     if (e.SubItem is ProgressListViewItem)
     {
         ProgressListViewItem item = (ProgressListViewItem)e.SubItem;
         if (item.ProgressBar.Visible = item.Project.IsBusy)
         {
             item.ProgressBar.Bounds = e.Bounds;
         }
     }
     e.DrawBackground();
     e.DrawText();
     //e.DrawDefault = true;
 }
        void LvInfoDrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            e.DrawBackground();

            if ((e.ItemState & ListViewItemStates.Selected) == ListViewItemStates.Selected)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
                e.SubItem.ForeColor = SystemColors.HighlightText;
            }
            else
            {
                e.SubItem.ForeColor = SystemColors.WindowText;
            }

            e.DrawText();
        }
Exemplo n.º 23
0
        // Handle DrawSubItem event
        private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            // This is the default text alignment
            TextFormatFlags flags =
                //TextFormatFlags.Left |
                //TextFormatFlags.NoPadding |
                TextFormatFlags.Default;


            // Align text on first column
            //if (e.ColumnIndex == 1) // && e.Item.Index > 11)
            //{
            //    flags = TextFormatFlags.Right;
            //}

            e.DrawText(flags);
        }
Exemplo n.º 24
0
 private void lvCamtasiaInfo_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
 {
     e.DrawBackground();
     e.DrawText();
     e.DrawFocusRectangle(e.Bounds);
     for (int i = 0; i < lvCamtasiaInfo.Items.Count; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             if (lvCamtasiaInfo.Items[i].SubItems[8].Text == "待入库")
             {
                 lvCamtasiaInfo.Items[i].SubItems[j].BackColor = Color.DarkGray;
                 lvCamtasiaInfo.Items[i].SubItems[j].ForeColor = Color.Red;
             }
         }
     }
 }
Exemplo n.º 25
0
 private void ListItems_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
 {
     if (!_HasOwnerDrawColumn)
     {
         e.DrawDefault = true;
         return;
     }
     if (e.ColumnIndex != 1)
     {
         e.DrawDefault = true;
         return;
     }
     //e.DrawBackground();
     e.Graphics.FillRectangle(Brushes.Aqua, e.SubItem.Bounds);
     e.DrawText();
     e.DrawDefault = false;
 }
Exemplo n.º 26
0
        private void stack_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            e.DrawBackground();
            if (e.Item.Selected)
            {
                e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds);
            }

            e.DrawText();

            SizeF size          = e.Graphics.MeasureString(e.SubItem.Text, modulesList.Font);
            int   requiredWidth = Math.Max(30, (int)size.Width + 20);

            if (modulesList.Columns[e.ColumnIndex].Width < requiredWidth)
            {
                modulesList.Columns[e.ColumnIndex].Width = requiredWidth + 5;
            }
        }
Exemplo n.º 27
0
        private void ListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            TextFormatFlags _textFormatFlags = TextFormatFlags.Left;

            using (StringFormat _stringFormat = new StringFormat())
            {
                // Store the column text alignment, letting it default
                // to Left if it has not been set to Center or Right.
                switch (e.Header.TextAlign)
                {
                case HorizontalAlignment.Center:
                    _stringFormat.Alignment = StringAlignment.Center;
                    _textFormatFlags        = TextFormatFlags.HorizontalCenter;
                    break;

                case HorizontalAlignment.Right:
                    _stringFormat.Alignment = StringAlignment.Far;
                    _textFormatFlags        = TextFormatFlags.Right;
                    break;
                }

                // Draw the text and background for a sub item with a
                // negative value.
                double _subItemValue;
                if ((e.ColumnIndex > 0) && double.TryParse(e.SubItem.Text, NumberStyles.Currency, NumberFormatInfo.CurrentInfo, out _subItemValue) && (_subItemValue < 0))
                {
                    // Unless the item is selected, draw the standard
                    // background to make it stand out from the gradient.
                    if ((e.ItemState & ListViewItemStates.Selected) == 0)
                    {
                        e.DrawBackground();
                    }

                    // Draw the sub item text in red to highlight it.
                    e.Graphics.DrawString(e.SubItem.Text, Font, Brushes.Red, e.Bounds, _stringFormat);

                    return;
                }

                // Draw normal text for a sub item with a non negative
                // or non numerical value.
                e.DrawText(_textFormatFlags);
            }
        }
Exemplo n.º 28
0
 protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
 {
     for (int i = 0; i < BoolColumn.Length; i++)
     {
         if (e.ColumnIndex == i)
         {
             if (BoolColumn[i])
             {
                 DrawSubItem(e.Graphics, e.SubItem);
             }
             else
             {
                 e.DrawText();
             }
             break;
         }
     }
     base.OnDrawSubItem(e);
 }
Exemplo n.º 29
0
        private void lvWindows_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            GameWindow window = Windows[e.ItemIndex];

            if (lastForegroundWindow == window.HWnd)
            {
                // Draw the background and focus rectangle for a selected item.
                e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds);
            }
            else if (ActiveWindow == window)
            {
                // Draw the background and focus rectangle for a selected item.
                e.Graphics.FillRectangle(
                    new SolidBrush(System.Drawing.SystemColors.Highlight),
                    e.Bounds
                    );
            }

            if (e.ColumnIndex == 0)
            {
                if (e.Item.Checked)
                {
                    ControlPaint.DrawCheckBox(e.Graphics, e.Bounds.X + 1, e.Bounds.Top + 1, 14, 14, ButtonState.Normal | ButtonState.Checked);
                }
                else
                {
                    ControlPaint.DrawCheckBox(e.Graphics, e.Bounds.X + 1, e.Bounds.Top + 1, 14, 14, ButtonState.Normal);
                }

                e.Graphics.DrawString(
                    e.Item.Text,
                    lvWindows.Font,
                    Brushes.Black,
                    new PointF(e.Bounds.X + 16, e.Bounds.Top + 1)
                    );
            }
            else
            {
                e.DrawText(TextFormatFlags.VerticalCenter | TextFormatFlags.Left);
            }
        }
Exemplo n.º 30
0
        private void listW_Danse_List_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            if (e.Item.Selected)
            {
                if (gListView1LostFocusItem == e.Item.Index)
                {
                    e.SubItem.ForeColor     = Color.White;
                    gListView1LostFocusItem = -1;
                }
                else
                {
                    e.SubItem.ForeColor = Color.White;
                }
            }
            else
            {
                e.SubItem.ForeColor = Color.Black;
            }

            e.DrawText();
        }
Exemplo n.º 31
0
 private void lvwSecurityGroup_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
 {
     if (e.Item.Selected)
     {
         e.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), e.Bounds);
         e.Graphics.DrawString(e.SubItem.Text, new Font("Tahoma", 8), new SolidBrush(Color.Black), e.Bounds);
     }
     else
     {
         e.DrawBackground();
         e.DrawText();
     }
 }