在选项卡之间切换时,每当我tabCurves
在初始输入后的任何时候输入控件时,都会System.IO.FileLoadException
在 line 处抛出a lstCurves_SelectedIndexChanged(Nothing, EventArgs.Empty)
。这对我来说完全莫名其妙,因为我有另一个 sub ( tabNURBS_Enter(...)
) 具有几乎相同的代码,但不会引发任何异常。
这里发生了什么?
代码:
Private Sub tabCurves_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabCurves.Enter
' See if the tab enter event is marked to be supressed...
If tabMain.Tag Is tabMain Then _
Exit Sub
With lstCurves.Items
' Remove old entries.
.Clear()
' Add new curves.
For I As Integer = 0 To m_NIS.Curves.Count - 1
.Add(m_NIS.Curves(I).Name)
Next I
End With
' Update selection.
lstCurves_SelectedIndexChanged(Nothing, EventArgs.Empty)
End Sub
Private Sub lstCurves_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstCurves.SelectedIndexChanged
If lstCurves.SelectedIndex = -1 Then
' Since no curve is selected, disable all UI controls except the add button.
' ### code snipped ###
' Reset fields.
' ### code snipped ###
Else
' Since a curve is selected, enable all UI controls.
' ### code snipped ###
' Update the fields.
' ### code snipped ###
' Force update of slider.
sldCURVKeyframes_ValueChanged(Nothing, EventArgs.Empty)
End If
End Sub
Private Sub sldCURVKeyframes_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles sldCURVKeyframes.ValueChanged
' Enable\Disable controls depending upon whether the slider is enabled or not.
' ### code snipped ###
End Sub
Private Sub tabNURBS_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabNURBS.Enter
' See if the tab enter event is marked to be supressed...
If tabMain.Tag Is tabMain Then _
Exit Sub
With lstNURBS.Items
' Remove old entries.
.Clear()
' Add new curves.
For I As Integer = 0 To m_NIS.BSplines.Count - 1
.Add(m_NIS.BSplines(I).Name)
Next I
End With
' Update selection.
lstNURBS_SelectedIndexChanged(Nothing, EventArgs.Empty)
End Sub
Private Sub lstNURBS_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstNURBS.SelectedIndexChanged
If lstNURBS.SelectedIndex = -1 Then
' Since no curve is selected, disable all UI controls except the add button.
' ### code snipped ###
' Reset fields.
' ### code snipped ###
Else
' Since a curve is selected, enable all UI controls.
' ### code snipped ###
' Update the fields.
' ### code snipped ###
' Force update of sliders.
sldNURBSCtlPoints_ValueChanged(Nothing, EventArgs.Empty)
sldNURBSKnots_ValueChanged(Nothing, EventArgs.Empty)
End If
End Sub
Private Sub sldNURBSCtlPoints_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles sldNURBSCtlPoints.ValueChanged
' Enable\Disable controls depending upon whether the slider is enabled or not.
' ### code snipped ###
' Update fields.
' ### code snipped ###
End Sub
Private Sub sldNURBSKnots_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles sldNURBSKnots.ValueChanged
' Enable\Disable controls depending upon whether the slider is enabled or not.
' ### code snipped ###
' Update fields.
' ### code snipped ###
End Sub
根据下面 Adrian 的评论,我决定窥探lstCurves_SelectedIndexChanged
并注释掉所有代码并减慢未注释的每一行,直到我发现问题(下面以粗体显示)。
Private Sub lstCurves_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstCurves.SelectedIndexChanged
If lstCurves.SelectedIndex = -1 Then
' Since no curve is selected, disable all UI controls except the add button.
btnCURVRemove.Enabled = False
btnCURVRename.Enabled = False
' Reset fields.
txtCURVPreInfinity.Text = ""
txtCURVPostInfinity.Text = ""
sldCURVKeyframes.Enabled = False
sldCURVKeyframes.Value = 0
sldCURVKeyframes.Maximum = 0
Else
' Since a curve is selected, enable all UI controls.
btnCURVRemove.Enabled = True
btnCURVRename.Enabled = True
' Update the fields.
With m_NIS.Curves(lstCurves.SelectedIndex)
txtCURVPreInfinity.Text = .PreInfinity
txtCURVPostInfinity.Text = .PostInfinity
sldCURVKeyframes.Enabled = True
sldCURVKeyframes.Maximum = .Keyframes.Count - 1
sldCURVKeyframes.Value = 0
End With
' Force update of slider.
sldCURVKeyframes_ValueChanged(Nothing, EventArgs.Empty)
End If
End Sub
Keyframes
是 type IList(Of Keyframe)
,它实际上是一个属性,它返回一个类型的内部列表EventList(Of T) Implements IList(Of T)
到 type的强制转换IList(Of Keyframe)
。EventList(Of T)
是一个包装器,当项目被添加、插入、移除、即将被移除、修改或列表被清除或即将被清除时抛出事件。
这会导致我遇到的问题吗?
这是定义 m_NIS 和动画曲线对象的相关文件。下载