如何画ListBoxItems之间的线(How do I draw a line between L

2019-09-16 09:18发布

我希望能够给每个项目在ListBox有横线分开。

这只是我的一些代码绘制的项目。

    private void symptomsList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
        bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);
        int index = e.Index;
        Graphics g = e.Graphics;
        Color color;
        if (selected == true)
        {
            color = Color.Red;
        }
        else
        {
            color = Color.Pink;
        }
        /* Draw Background */
        g.FillRectangle(new SolidBrush(color), e.Bounds);

        /* Draw Item Text */
        g.DrawString(symptomsList.Items[e.Index].ToString(), e.Font, new SolidBrush(Color.Black), e.Bounds, StringFormat.GenericDefault);

        e.DrawFocusRectangle();
    }

Answer 1:

之后FillRectangle(...)使用此:

Color borderColor = Color.Black;
g.DrawRectangle(new Pen(borderColor), e.Bounds);


文章来源: How do I draw a line between ListBoxItems