VB 2013中的奇怪错误? [英] Odd bug in VB 2013??

查看:89
本文介绍了VB 2013中的奇怪错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

弹出的对话框显示以下内容:

The dialog that pops up states the following:

托管调试助手"CallbackOnCollectedDelegate"在"C:\ Users \ Dadman \ Documents \ Visual Studio 2013 \ Projects \ EGTest2 \ EGTest2 \ bin \ Debug \ EGTest2.vshost.exe"中检测到问题.

Managed Debugging Assistant 'CallbackOnCollectedDelegate' has detected a problem in 'C:\Users\Dadman\Documents\Visual Studio 2013\Projects\EGTest2\EGTest2\bin\Debug\EGTest2.vshost.exe'.

其他信息:对类型为'System.Windows.Forms!System.Windows.Forms.NativeMethods + WndProc :: Invoke'的垃圾收集的委托进行了回调.这可能会导致应用程序崩溃,损坏和数据丢失.将代表传递给 非托管代码,它们必须由托管应用程序保持活动状态,直到确保永远不会调用它们为止.

Additional information: A callback was made on a garbage collected delegate of type 'System.Windows.Forms!System.Windows.Forms.NativeMethods+WndProc::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.

此外,在另一个窗口中,还会显示以下消息..

Also, in another window the following message appears.

由于本机框架位于调用堆栈的顶部,因此无法评估表达式. VB 2013

该程序是实例化的一类,并作为控件添加到表单上.该类是一个Panel控件,具有在其上实例化的两个TableLayoutPanels.照原样,这两个表只有一行(计划动态添加更多后来).控制 表格有两列,而条"桌子只有一个.控制表的每一行都包含一个文本框和一个组合框.剥离表仅包含标签.

The program is one class instanced and added as a control on a form.  The class is a Panel control with two TableLayoutPanels instanced on it.  As is, the two tables have only one row (plan to dynamically add more later)  The control table has two columns, and the "strip" table has only one.  Each row of the control table contains a text box and a combo box.  The strip table only contains labels.

第一段代码显示了构造器的一部分,该构造器构建了Label所在的Panel的一部分:

The 1st block of code shows the part of the constructor that builds the part of the Panel that the Label resides in:

StripTable和ControlTable是TableLayoutPanels,myWoodPanel是Panel容器.

StripTable and ControlTable are TableLayoutPanels, myWoodPanel is a Panel container.

Dim label1 As New Label AddHandler label1.Click, AddressOf LabelClick AddHandler label1.MouseWheel, AddressOf LabelMouseWheel AddHandler label1.Leave, AddressOf LabelLeave label1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top label1.Text = "None" label1.TextAlign = ContentAlignment.MiddleCenter label1.BackColor = Color.LavenderBlush myStripTable.Controls.Add(label1, 0, 0) myWoodPanel.Controls.Add(myControlTable) myWoodPanel.Controls.Add(myStripTable)

结束子

这是标签的三个事件处理程序.

These are the three event handlers for the label.

  Private Sub LabelClick(sender As Object, e As EventArgs)
        Dim SelectedLabel As Label = sender
        SelectedRow = myStripTable.GetRow(sender)
        If SelectedLabel.BorderStyle = BorderStyle.None Then
            SelectedLabel.BorderStyle = BorderStyle.Fixed3D
            SelectedLabel.Focus()
        Else
            SelectedLabel.BorderStyle = BorderStyle.None
        End If
    End Sub

    Private Sub LabelLeave(sender As Object, e As EventArgs)
        Dim SelectedLabel As Label = sender
        SelectedRow = myStripTable.GetRow(sender)
        SelectedLabel.BorderStyle = BorderStyle.None
    End Sub

    Private Sub LabelMouseWheel(sender As Object, e As MouseEventArgs)
        Dim myTxtBox As TextBox = myControlTable.GetControlFromPosition(0, SelectedRow)
        Dim SelectedLabel As Label = sender
        Dim StripWidth As Double = CDbl(myTxtBox.Text)

        If e.Delta > 0 Then
            StripWidth += 0.125
        Else
            If StripWidth <= 0.125 Then Exit Sub
            StripWidth -= 0.125
        End If
        myTxtBox.Text = CStr(StripWidth)
        myStripTable.RowStyles(SelectedRow).Height = CInt(StripScale * StripWidth)
    End Sub

主要形式

Public Class EGTest2
 
    Dim WoodPanel1 As WoodPanel

    Private Sub EGTest2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        WoodPanel1 = New WoodPanel()
        Me.Controls.Add(WoodPanel1.myWoodPanel)

    End Sub
End Class

通过实验,我发现放置在Main窗体上的标签如果被重复单击,则不会触发Leave事件,而Panel上TableLayoutPanel上的标签却会触发.如果单击表中的标签时会发生异常 已经有重点了.如果我注释掉"SelectedLabel.Focus", Label.Click处理程序中的语句,则不会发生该异常.在标签具有焦点的情况下单击标签时,我一直在跟踪代码.标签离开 事件首先得到处理,然后立即转到Label.Click.看来控件的对象内存已被收集或已损坏.文本字段为空,但颜色字段仍然正确.

Through experimentation, I found that a label placed on the Main form does not trigger the Leave event if repetitively clicked, whereas the label on the TableLayoutPanel on the Panel does. The exception occurs if the Label in the Table is clicked when it already has focus.  If I comment out the "SelectedLabel.Focus" statement in the Label.Click handler, the exception does not occur.  I traced the code through while clicking on the label when it is clicked while it has focus.  The Label.Leave event is serviced first, then it goes immediately to Label.Click.  It appears the object memory for the control has either been collected or corrupted.  The text field is nulled, but the color field is still correct.

如果我没有在表格"焦点中给出标签",则该标签不会发生鼠标滚轮事件.

If I don't give the Label in the Table focus, the mouse wheel events do not occur for the label.

如果有人有解决方法的想法,我会很高兴.

If anyone has workaround ideas, I'm all ears.

迈克

推荐答案

迈克

我还没有仔细看过,但这会引起问题:

I haven't looked all through this, but this will cause an issue:

Dim SelectedLabel As Label = sender

相反,将其强制转换为类型:

Instead, cast it to a type:

将selectedLabel标记为标签= DirectCast(发送方,标签)

尝试纠正所有这些问题,看看情况是否有所改善?

Try to correct all of those and see if the situation improves?


这篇关于VB 2013中的奇怪错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆