commondialog 是一种类型,不能用作表达式

commondialog is a type and cannot be used as an expression

这是我第一次真正接触 .NET,如果这是一个愚蠢的问题,请提前致歉。我正在将 VB6 升级到 .NET(使用 VS 2008)。

我收到错误消息“Commondialog 是一种类型,不能用作表达式

有人能帮帮我吗?如果可能的话,你能提供一个完整的答案吗,因为我很容易混淆!

干杯!

密码是:

Private Sub cmdBrowse_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBrowse.Click
    'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
    With CommonDialog
        .InitialDirectory = My.Application.Info.DirectoryPath
        'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
        .Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*"
        .FilterIndex = 1
        'UPGRADE_WARNING: FileOpenConstants constant FileOpenConstants.cdlOFNHideReadOnly was upgraded to OpenFileDialog.ShowReadOnly which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
        'UPGRADE_WARNING: MSComDlg.CommonDialog property CommonDialog.Flags was upgraded to CommonDialogOpen.CheckFileExists which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
        .CheckFileExists = True
        .CheckPathExists = True
        'UPGRADE_WARNING: MSComDlg.CommonDialog property CommonDialog.Flags was upgraded to CommonDialogOpen.ShowReadOnly which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
        'UPGRADE_WARNING: FileOpenConstants constant FileOpenConstants.cdlOFNHideReadOnly was upgraded to OpenFileDialog.ShowReadOnly which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
        .ShowReadOnly = False
        .FileName = txtEnterValue.Text
        .ShowDialog()
        txtEnterValue.Text = .FileName
    End With
    RefreshFileDetails()
End Sub

改用OpenFileDialog

Private Sub cmdBrowse_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBrowse.Click
    Using ofd As New OpenFileDialog
        ofd.InitialDirectory = My.Application.Info.DirectoryPath
        ofd.Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*"
        ofd.CheckFileExists = True
        ofd.ShowReadOnly = True
        ofd.FileName = txtEnterValue.Text
        If ofd.ShowDialog = DialogResult.OK Then
            txtEnterValue.Text = ofd.FileName
            RefreshFileDetails()
        End If
    End Using
End Sub