首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ListBoxItems之间划线

如何在ListBoxItems之间划线
EN

Stack Overflow用户
提问于 2012-04-07 12:34:50
回答 2查看 2.4K关注 0票数 2

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

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

代码语言:javascript
复制
    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();
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-07 14:04:57

FillRectangle(...)之后,使用以下命令:

代码语言:javascript
复制
Color borderColor = Color.Black;
g.DrawRectangle(new Pen(borderColor), e.Bounds);
票数 3
EN

Stack Overflow用户

发布于 2020-04-29 10:00:10

//在InitializeComponent()后添加此行;symptomsList.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10051781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档