问题
This code was converted from VB6 to VB.Net:
Public prvMainForm = VB6Form
If prvMainForm IsNot Nothing Then
CObj(prvMainForm).StatusBar.Panels(1) = "Initializing Folders..."
End If
(My code is quite long so I've just added this if block which is where the actual error occurs.)
The error is seen on the single line inside the If statement:
Property 'Item' is 'ReadOnly'
回答1:
StatusBar.Panels(1) returns a MSComctlLib.Panel.
StatusBar.Panels(1) = "Initializing Folders..." is valid in VB6 because of default properties.
Default properties in VB.NET must have parameters. A parameterless property cannot be default and therefore cannot be omitted. Thus, .Panels(1) = "..." is understood by VB.NET as an attempt to replace the entire Panel in the Panels property, which is not allowed.
You can look up the name of the default property in the VB6 object browser, which turns out to be Property _ObjectDefault As String, so you should be able to do:
CObj(prvMainForm).StatusBar.Panels(1).[_ObjectDefault] = "Initializing Folders..."
As you have observed, assigning Text should do the same:
CObj(prvMainForm).StatusBar.Panels(1).Text = "Initializing Folders..."
来源:https://stackoverflow.com/questions/59720936/setting-default-property-fails-because-it-is-read-only