ListBox. Как увеличить высоту предмета? - PullRequest
0 голосов
/ 16 января 2019

Я пытаюсь увеличить высоту предмета, но не могу.
Я использую события listBox1_DrawItem и listBox1_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 голосов
/ 16 января 2019

Из документов .

// Set the DrawMode property to the OwnerDrawVariable value. 
// This means the MeasureItem and DrawItem events must be 
// handled.
ListBox1.DrawMode = DrawMode.OwnerDrawVariable;
ListBox1.MeasureItem += new MeasureItemEventHandler(ListBox1_MeasureItem);

Вам нужно изменить DrawMode, чтобы вызвать MeasureEvent, где вы обновите высоту списка.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...