来自模块的VB.NET控件表单

时间:2012-06-20 05:03:19

标签: vb.net

我最近将我的项目从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

1 个答案:

答案 0 :(得分: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参数类型。

  

问题是模块中的sub不仅被“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