How do I draw a line between ListBoxItems

╄→гoц情女王★ 提交于 2019-12-12 19:49:26

问题


I want to be able to separate each item in a listbox with a horizontal line.

This is just some of my code for drawing the items.

    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();
    }

回答1:


After FillRectangle(...) use this:

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


来源:https://stackoverflow.com/questions/10051781/how-do-i-draw-a-line-between-listboxitems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!