C# 如何在ListBoxItems之间划一条线

C# 如何在ListBoxItems之间划一条线,c#,winforms,listbox,C#,Winforms,Listbox,我希望能够用水平线分隔列表框中的每个项目 这只是我绘制项目的部分代码 private void symptomsList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected); int index = e

我希望能够用水平线分隔列表框中的每个项目

这只是我绘制项目的部分代码

    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();
    }
在填充矩形之后。。。使用以下命令:

Color borderColor = Color.Black;
g.DrawRectangle(new Pen(borderColor), e.Bounds);
在填充矩形之后。。。使用以下命令:

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

//在InitializeComponent之后添加此行;
SymplesList.DrawMode=System.Windows.Forms.DrawMode.OwnerDrawVariable

//在InitializeComponent之后添加此行; SymplesList.DrawMode=System.Windows.Forms.DrawMode.OwnerDrawVariable