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

时间:2015-10-19 02:54:22

标签: vb.net vb6-migration

这是我在.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

1 个答案:

答案 0 :(得分:1)

改为使用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