C# 参数无效
我收到错误消息: 参数无效 从这一行:C# 参数无效,c#,winforms,C#,Winforms,我收到错误消息: 参数无效 从这一行: e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds); 以下是我的绘图功能: private int mouseIndex = -1; private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) return; Brush textBrush = SystemBrush
e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
以下是我的绘图功能:
private int mouseIndex = -1;
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index == -1) return;
Brush textBrush = SystemBrushes.WindowText;
if (e.Index > -1)
{
if (e.Index == mouseIndex)
{
e.Graphics.FillRectangle(SystemBrushes.HotTrack, e.Bounds);
textBrush = SystemBrushes.HighlightText;
}
else
{
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
textBrush = SystemBrushes.HighlightText;
}
else
{
// This Line:
e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
}
}
e.Graphics.DrawString(contact.P_DISPLAYNAME,
e.Font, textBrush, e.Bounds.Left + 20, e.Bounds.Top);
}
}
你提供的信息太少了。可能e.Bounds不是有效的矩形。(矩形为0或null)。代码的其余部分是什么?你要做什么?多加一点上下文会增加你的更改,以获得一个好的解决方案。我尝试drawItem,但消息指向这一行,我想把我的代码放在哪里,我可以把它放在我的问题上。你可以单击编辑链接并更新问题。任何人都可以帮助我,我在上面发布了我的代码,但获取的错误参数无效!,在这一行:这是输入代码。实际上,我以前用这段代码来drawItem,当我将对象类添加到ListBox中时,它是有效的,但现在我的数据是json,我用foreach读取json索引,然后添加ListBox.items.add(data),然后再添加drawItem。ListBox中的数据对象和json之间是否可能发生错误?可能是插入的数据为空。(也许您做了错误的JSON转换)我应该如何将JSON读入易于放入的列表框?我的json类似于数据[{name=“…”,email=“…”},{name=“…”,email=“…”}],我建议用更多信息和源示例问一个新问题。