设置默认属性失败,因为它是只读的? [英] Setting default property fails because it is read only?

查看:35
本文介绍了设置默认属性失败,因为它是只读的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码已从 VB6 转换为 VB.Net:

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

(我的代码很长,所以我刚刚添加了这个 if 块,它是实际发生错误的地方.)

(My code is quite long so I've just added this if block which is where the actual error occurs.)

错误出现在 If 语句中的单行:

The error is seen on the single line inside the If statement:

属性项目"是只读"

推荐答案

StatusBar.Panels(1) 返回一个 MSComctlLib.Panel.

StatusBar.Panels(1) = "Initializing Folders..." 在 VB6 中有效,因为 默认属性.

StatusBar.Panels(1) = "Initializing Folders..." is valid in VB6 because of default properties.

VB.NET 中的默认属性必须有参数.无参数属性不能是默认值,因此不能省略.因此,.Panels(1) = "..." 被VB.NET 理解为试图替换PanelsPanel> 属性,这是不允许的.

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.

你可以在VB6对象浏览器中查找默认属性的名称,结果是Property _ObjectDefault As String,所以你应该可以这样做:

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..."

正如您所观察到的,分配 Text 应该做同样的事情:

As you have observed, assigning Text should do the same:

CObj(prvMainForm).StatusBar.Panels(1).Text = "Initializing Folders..."

这篇关于设置默认属性失败,因为它是只读的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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