【问题标题】:How do I draw a line between ListBoxItems如何在 ListBox 项之间画一条线
【发布时间】:2012-04-07 04:34:50
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# winforms listbox


    【解决方案1】:

    //在InitializeComponent()之后添加这一行; 症状列表.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;

    【讨论】:

      【解决方案2】:

      FillRectangle(...) 之后使用这个:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-01
        • 1970-01-01
        • 2020-02-16
        相关资源
        最近更新 更多