我正在尝试创建一个包含可变大小项的ListBox。我有这么多工作,如下所示:
但正如你所看到的,第一项似乎被忽略了。 这里发生了什么以及我如何使它也受到ItemHeight属性的影响? 我的代码如下所示:
private void ClassicEvent_Load(object sender, EventArgs e)
{
eventCommands.DrawMode = DrawMode.OwnerDrawVariable;
eventCommands.MeasureItem += EventCommands_MeasureItem;
eventCommands.DrawItem += EventCommands_DrawItem;
eventCommands.Items.Add("Text: I heard you were going to the Pokémon Centre.");
eventCommands.Items.Add("if (Has Pokemon (Bulbasaur) in PC)");
eventCommands.Items.Add(" Text: You have a Bulbasaur.");
eventCommands.Items.Add("else");
eventCommands.Items.Add(" Text: You don't have a Bulbasaur.");
eventCommands.Items.Add("end");
eventCommands.Items.Add("Text: So be it, then.");
}
private void EventCommands_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
e.Graphics.DrawString(eventCommands.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
e.DrawFocusRectangle();
}
private void EventCommands_MeasureItem(object sender, MeasureItemEventArgs e)
{
eventCommands.ItemHeight = 48;
}
我已经尝试更改e.Bounds
矩形,如果迭代的项目是第一个,也尝试更改ItemHeight,但我无法理解。
答案 0 :(得分:1)
在<p id="p">
Several
lines
of text
</p>
中,显然EventCommands_MeasureItem
还包含MeasureItemEventArgs e
属性。使用 工作。