列表框。如何增加身高项目?

时间:2019-01-16 19:35:24

标签: c# winforms

我试图增加物品的高度,但是我不能。
我使用listBox1_DrawItemlistBox1_MeasureItem事件。
代码。

    private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
            {
                e.DrawBackground();
                e.DrawFocusRectangle();

                // You'll change the font size here. Notice the 20
                // e.Graphics.DrawString(e.Index, new Font(FontFamily.GenericSansSerif, 20, FontStyle.Bold), new SolidBrush(e.Index), e.Bounds);

                //e.Graphics.DrawString(listBox1.Items[e.Index].ToString,
                //                     listBox1.Font, Brushes.Black,
                //                     e.Bounds.Left, (
                //                     (e.Bounds.Height - listBox1.Font.Height)) + e.Bounds.Top);

                // e.DrawBackground(); //Draw our regular background

                // e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), 1, listBox1.Items[e.Index].ToString().Length - 1), e.Font, Brushes.Red, e.Bounds);    //Draw the item text in red!

                // e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, Brushes.Black, e.Bounds); //Draw the item text in its regular color

                    // e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), 1, listBox1.Items[e.Index].ToString().Length - 1), e.Font, Brushes.Red, e.Bounds);    //Draw the item text in red!

                    e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, Brushes.Black, e.Bounds); //Draw the item text in its regular color



            }

            private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
            {
                e.ItemHeight = 25;
            }
public void InfoError()
        {
            string info = "Ошибка";
            listBox1.ItemHeight = 60; 

            listBox1.Items.Add(info);
        }

          public void InfoSuccess()
            {
                string info = "Успех";
                listBox1.Items.Add(info);

            }
     // Ошибка
            private void button1_Click(object sender, EventArgs e)
            {
                InfoError();
            }

            // Успех
            private void button2_Click(object sender, EventArgs e)
            {
                InfoSuccess();
            }

问题。
1.增加“项目”高度(项目)还是“项目”之间的距离?

1 个答案:

答案 0 :(得分:0)

来自docs

shipmentItem

您需要更改DrawMode才能调用MeasureEvent,您将在其中更新列表框的高度。