我有一个使用控件列表构建的表单。但是,它们通过删除和重建这些控件来刷新这些控件中的数据。这就是它变得敏感的地方。当我第一次单击另一个文本框时发生错误,该文本框触发了前一个文本框的离开事件,该文本框调用清理功能以重建所有控件。单击的文本框包含在已销毁项目的列表中,这就是发生错误“无法访问已处理的对象命名”的原因。但是,我只是不知道在哪里处理 System.ObjectDisposedException,因为我无法在创建表单时捕获它。
这是崩溃日志
System.ObjectDisposedException: Can not access a disposed object named "TextBox".
Object name: "TextBox".
Has System.Windows.Forms.Control.CreateHandle ()
Has System.Windows.Forms.TextBoxBase.CreateHandle ()
Has System.Windows.Forms.Control.get_Handle ()
Has System.Windows.Forms.Control.set_CaptureInternal (Boolean value)
Has System.Windows.Forms.Control.WmMouseDown (Message & m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc (Message & m)
Has System.Windows.Forms.TextBoxBase.WndProc (Message & m)
Has System.Windows.Forms.TextBox.WndProc (Message & m)
Has System.Windows.Forms.ControlNativeWindow.OnMessage (Message & m)
Has System.Windows.Forms.ControlNativeWindow.WndProc (Message & m)
at System.Windows.Forms.NativeWindow.Callback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我也尝试使用该语句if Control.Isdisposed then return
,但似乎 leave 或 mousedown 事件并不关心它:S
你们能帮我找到我可以在这个表格上处理这个错误的地方吗?我无法通过调试来跟踪它,它只是在 End Sub 之后弹出。
在 vb.net FrameWorks 1.1 中编码
这是我销毁目标对象的代码
Private Sub viderRecursiveStack(ByVal control As Control)
Dim stack As New stack
Dim ctl As control
Dim enfantAssocie As ArrayList
stack.Push(control)
While stack.Count > 0
ctl = CType(stack.Pop, control)
If Not ctl Is Nothing Then
If TypeOf ctl Is Panel Then
'Cree la liste des enfants associés
enfantAssocie = New ArrayList(ctl.Controls)
For Each ctli As control In enfantAssocie
If Not TypeOf ctli Is EasyDeal.Controls.EasyDealLabel3D AndAlso** Not TypeOf ctli Is EasyDeal.Controls.EasyDealButton Then
stack.Push(ctli)
ctl.Controls.Remove(ctli)
End If
Next
Else
RemoveHandler ctl.Leave, AddressOf txtEquipAddCommissionChanged
ctl.Dispose()
End If
End If
End While
End Sub