我有一个从 VB6 转换为 VB.Net 的项目,它使用 .NET 4.5.2 和 BaseControlArray 问题

I have a project Converted from VB6 to VB.Net that uses .NET 4.5.2 with a BaseControlArray Issue

好的,我在 VB6 版本的窗体上有一个 Line Control,但是转换在它上面单独创建了一个文件。编译输出有效,但它带有一个警告,我想删除 4.6+ 支持,如果 Miscorsoft.VisualBasic.Compatibility 被删除,我可以不引用它。

Option Strict Off
Option Explicit On
Imports System.Windows.Forms
Imports System.ComponentModel
Imports Microsoft.VisualBasic.Compatibility.VB6
Imports Microsoft.VisualBasic.PowerPacks

<ProvideProperty("Index", GetType(LineShape))> Friend Class LineShapeArray
    Inherits BaseControlArray
    Implements IExtenderProvider

    Public Event [Click] As EventHandler

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal Container As IContainer)
        MyBase.New(Container)
    End Sub

    Public Function CanExtend(ByVal Target As Object) As Boolean Implements IExtenderProvider.CanExtend
        If TypeOf Target Is LineShape Then
            Return BaseCanExtend(Target)
        End If
        Return 0
    End Function

    Public Function GetIndex(ByVal o As LineShape) As Short
        Return BaseGetIndex(o)
    End Function

    Public Sub SetIndex(ByVal o As LineShape, ByVal Index As Short)
        BaseSetIndex(o, Index)
    End Sub

    Public Function ShouldSerializeIndex(ByVal o As LineShape) As Boolean
        Return BaseShouldSerializeIndex(o)
    End Function

    Public Sub ResetIndex(ByVal o As LineShape)
        BaseResetIndex(o)
    End Sub

    Public Shadows Sub Load(ByVal Index As Short)
        MyBase.Load(Index)
        CType(Item(0).Parent, ShapeContainer).Shapes.Add(Item(Index))
    End Sub

    Public Shadows Sub Unload(ByVal Index As Short)
        CType(Item(0).Parent, ShapeContainer).Shapes.Remove(Item(Index))
        MyBase.Unload(Index)
    End Sub

    Public Default ReadOnly Property Item(ByVal Index As Short) As LineShape
        Get
            Item = CType(BaseGetItem(Index), LineShape)
        End Get
    End Property

    Protected Overrides Sub HookUpControlEvents(ByVal o As Object)
        Dim ctl As LineShape
        ctl = CType(o, LineShape)
        If Not IsNothing(ClickEvent) Then
            AddHandler ctl.Click, ClickEvent
        End If
    End Sub

    Protected Overrides Function GetControlInstanceType() As System.Type
        Return GetType(LineShape)
    End Function
End Class

和警告:

warning BC40000: 'BaseControlArray' is obsolete: 'Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only. http://go.microsoft.com/fwlink/?linkid=160862'.

警告中的 link 实际上对修复此警告根本没有帮助。

我最终在表单的绘制事件中执行了此操作,该事件使用了我标记的以下问题的答案之后的行:

    Private Sub Form2_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
        e.Graphics.DrawLine(Pens.Gray, 0, 151, Me.Width, 151)
        e.Graphics.DrawLine(Pens.White, 0, 152, Me.Width, 152)
    End Sub

y1y2中的值DrawLine可以替换成想要的表格高度。 Pens 颜色相同。

没有您可以使用的直接等价物。

See here for someone who had the same issue

And resolved it using this

我看到三个问题:控件数组、行控件、使用 Microsoft.VisualBasic.Compatibility。

  1. 使用避免控制数组。

  2. 用.Net画线方法替换Line控件as explained here。我建议您不要使用 Power Pack Line Control,因为 Power Pack 不再更新。

  3. 最好停止使用 Microsoft.VisualBasic.Compatibility 以防它被淘汰,但我个人会考虑先让整个项目工作(如有必要,使用 Microsoft.VisualBasic.Compatibility) ,然后设法将其删除。