0

我最近将我的项目从 VB6 转换为 VB.NET2008,在这里转换后是一个从我创建的模块控制表单的子,错误类似于

“cmdAdd 不是 System.Windows.Forms.Form 的成员”

Public Sub ButtonSet(ByRef frmObj As System.Windows.Forms.Form)
    frmObj.cmdAdd.Visible = True
    frmObj.cmdCopy.Visible = True
    frmObj.cmdEdit.Visible = True
    frmObj.cmdCorrection.Visible = True
End Sub

它是如何调用的:

Private Sub frmAPNote_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
ButtonSet(Me)
End Sub
4

1 回答 1

1

将参数类型更改为YourFormName

Public Sub ButtonSet(ByRef frmObj As frmAPNote)
    frmObj.cmdAdd.Visible = True
    frmObj.cmdCopy.Visible = True
    frmObj.cmdEdit.Visible = True
    frmObj.cmdCorrection.Visible = True
End Sub

PS:不需要为对象指定 ByRef 参数类型。

问题是模块中的子不仅被“frmAPNote”调用,还被其他形式如“frmARNote”和“frmRTNote”调用

Form.Controls您可以从集合中获取特定控件的引用。

Public Sub ButtonSet(ByVal frmObj As Form)
    Dim btnAdd = frmObj.Controls("btnAdd")

    If Not IsNothing(btnAdd) Then
        btnAdd.Visible = False
    End If

    ....
End Sub
于 2012-06-20T05:05:14.833 回答