Exemplo n.º 1
0
    private void ListBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
        if (e.Index == -1)
        {
            return;
        }
        int i = System.Convert.ToInt32(ListBox1.Items[e.Index]);

        e.DrawBackground();
        if (i % 4 != 0)
        {
            string spaces = new string(' ', 20);
            e.Graphics.DrawString(
                "Item #: " + i.ToString() + spaces.Replace(" ", " <Filler>"),
                ListBox1.Font,
                System.Drawing.Brushes.Black,
                0,
                e.Bounds.Top);
        }
        else
        {
            e.Graphics.DrawLine(
                System.Drawing.Pens.Blue,
                10,
                e.Bounds.Top + 1,
                52,
                e.Bounds.Top + 1);
        }
        e.DrawFocusRectangle();
    }
Exemplo n.º 2
0
        //protected override void OnMeasureItem(System.Windows.Forms.MeasureItemEventArgs e)
        //{
        //    base.OnMeasureItem(e);
        //    e.ItemHeight = e.ItemHeight - 2;
        //}

        protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
        {
            base.OnDrawItem(e);
            if (e.Index < 0)
            {
                return;
            }
            float size = this.Font.Size;

            System.Drawing.Font       myFont;
            System.Drawing.FontFamily family = this.Font.FontFamily;

            System.Drawing.Color animalColor = this.ForeColor;

            // Draw the background of the item.
            e.DrawBackground();

            // Create a square filled with the animals color. Vary the size
            // of the rectangle based on the length of the animals name.
            //System.Drawing.Rectangle rectangle = new Rectangle(2, e.Bounds.Top + 2,
            //        e.Bounds.Height, e.Bounds.Height - 4);
            //e.Graphics.FillRectangle(new SolidBrush(animalColor), rectangle);

            // Draw each string in the array, using a different size, color,
            // and font for each item.
            myFont = new Font(family, size, FontStyle.Regular);

            e.Graphics.DrawString(this.GetItemText(Items[e.Index]), myFont, System.Drawing.Brushes.Black, new PointF(e.Bounds.X + 5, e.Bounds.Y + 2));
            //new RectangleF(e.Bounds.X + e.Bounds.Height, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
            //弹出下拉
            //if (e.State == (System.Windows.Forms.DrawItemState.NoAccelerator | System.Windows.Forms.DrawItemState.NoFocusRect))
            //{
            //    e.Graphics.DrawRectangle(new Pen(_borderColor), e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
            //}
            //else//选择时
            //{
            //    e.Graphics.DrawRectangle(new Pen(_borderColor), e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1);
            //}
            // Draw the focus rectangle if the mouse hovers over an item.
            e.DrawFocusRectangle();
        }
Exemplo n.º 3
0
        protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
        {
            e.DrawBackground();

            if (e.State == System.Windows.Forms.DrawItemState.Focus)
            {
                e.DrawFocusRectangle();
            }

            if (e.Index < 0 || e.Index >= Items.Count)
            {
                return;
            }

            string text = (Items[e.Index] == null) ? "(null)" : Items[e.Index].ToString();

            using (System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(e.ForeColor))
            {
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                e.Graphics.DrawString(text, e.Font, brush, e.Bounds);
            }
        }
Exemplo n.º 4
0
    protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
    {
        e.DrawBackground();
        e.DrawFocusRectangle();
        GListBoxItem item;
        Rectangle    bounds    = e.Bounds;
        Size         imageSize = _myImageList.ImageSize;

        try
        {
            item = (GListBoxItem)Items[e.Index];
            if (item.ImageIndex != -1)
            {
                imageList.Draw(e.Graphics, bounds.Left, bounds.Top, item.ImageIndex);
                e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor),
                                      bounds.Left + imageSize.Width, bounds.Top);
            }
            else
            {
                e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor),
                                      bounds.Left, bounds.Top);
            }
        }
        catch
        {
            if (e.Index != -1)
            {
                e.Graphics.DrawString(Items[e.Index].ToString(), e.Font,
                                      new SolidBrush(e.ForeColor), bounds.Left, bounds.Top);
            }
            else
            {
                e.Graphics.DrawString(Text, e.Font, new SolidBrush(e.ForeColor),
                                      bounds.Left, bounds.Top);
            }
        }
        base.OnDrawItem(e);
    }
    private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
        Brush brush;

        // Create the brush using the ForeColor specified by the DrawItemEventArgs
        if (foreColorBrush == null)
        {
            foreColorBrush = new SolidBrush(e.ForeColor);
        }
        else if (foreColorBrush.Color != e.ForeColor)
        {
            // The control's ForeColor has changed, so dispose of the cached brush and
            // create a new one.
            foreColorBrush.Dispose();
            foreColorBrush = new SolidBrush(e.ForeColor);
        }

        // Select the appropriate brush depending on if the item is selected.
        // Since State can be a combinateion (bit-flag) of enum values, you can't use
        // "==" to compare them.
        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
        {
            brush = SystemBrushes.HighlightText;
        }
        else
        {
            brush = foreColorBrush;
        }

        // Perform the painting.
        Font font = ((ListBoxFontItem)listBox1.Items[e.Index]).Font;

        e.DrawBackground();
        e.Graphics.DrawString(font.Name, font, brush, e.Bounds);
        e.DrawFocusRectangle();
    }