我如何在ListBoxItems之间画一条线 [英] How do I draw a line between ListBoxItems
本文介绍了我如何在ListBoxItems之间画一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够用水平线分隔列表框中的每个项目.
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();
}
推荐答案
在 FillRectangle(...) 之后,使用此命令:
After FillRectangle(...) use this:
Color borderColor = Color.Black;
g.DrawRectangle(new Pen(borderColor), e.Bounds);
这篇关于我如何在ListBoxItems之间画一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文