首页 > 解决方案 > 索引超出范围...为什么会出现此错误?我不使用那个

问题描述

我收到错误... System.Collections.ArrayList.get_Item(Int32 index) 索引超出范围。必须是非负数且小于集合的大小

=================================================

Exception Desc >> Time[20180721_04:44:07] Message[Index was out of range. Must be non-negative and less than the size of the collection 매개 변수 이름: index] Source[mscorlib]StackTrace[   위치: System.Collections.ArrayList.get_Item(Int32 index)
   위치: System.Windows.Forms.ToolStripItemCollection.get_Item(Int32 index)
   위치: System.Windows.Forms.ToolStrip.OnPaint(PaintEventArgs e)
   위치: System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   위치: System.Windows.Forms.Control.WmPaint(Message& m)
   위치: System.Windows.Forms.Control.WndProc(Message& m)
   위치: System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   위치: System.Windows.Forms.ToolStrip.WndProc(Message& m)
   위치: System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   위치: System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   위치: System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)]

=================================================

为什么我得到这个错误???我不使用 System.Collections.ArrayList.get_Item(int32 Index)

这是我的源代码的一部分,错误点

private System.Windows.Forms.ToolStripLabel base_MessageBar;
...
public void MyFunctionAtErrorPoint(String str)
{
    if (base_MessageBar.ForeColor != Color.Black) base_MessageBar.ForeColor= Color.Black;
    this.base_MessageBar.Text = str;
}

标签: c#winformsarraylistindexing

解决方案


我通过使用调用函数解决了这个错误

我在非 UI 线程中设置了一些 UI 值...

我希望这篇文章对某人有帮助......


推荐阅读