我试图增加物品的高度,但是我不能。
我使用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.增加“项目”高度(项目)还是“项目”之间的距离?