Vb.net 如何在“中显示打开的文件名”;另存为;使用Visual Basic的对话框?

Vb.net 如何在“中显示打开的文件名”;另存为;使用Visual Basic的对话框?,vb.net,Vb.net,我正在学习Visual Basic,我需要知道当我在GUI上单击“保存”并弹出“保存”对话框时,当前打开的文件名已显示在“文件名:xxxxxx”中 这就是我到目前为止所做的: 导入System.IO 公开课表格1 Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim dr As DialogResult dr = dlgSav

我正在学习Visual Basic,我需要知道当我在GUI上单击“保存”并弹出“保存”对话框时,当前打开的文件名已显示在“文件名:xxxxxx”中

这就是我到目前为止所做的: 导入System.IO 公开课表格1

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
    Dim dr As DialogResult
    dr = dlgSave.ShowDialog()
    If dr = Windows.Forms.DialogResult.OK Then
        Dim writerVar As StreamWriter
        writerVar = New StreamWriter(dlgSave.FileName, False)
        writerVar.Write(txtEdit.Text)
        writerVar.Close()
    End If
End Sub
干杯,
Alex

这应该可以帮助您:

        ' Shows the use of a SaveFileDialog to save a MemoryStream to a file.
Private Sub Button2_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles Button2.Click

    ' Set the properties on SaveFileDialog1 so the user is 
    ' prompted to create the file if it doesn't exist 
    ' or overwrite the file if it does exist.
    SaveFileDialog1.CreatePrompt = True
    SaveFileDialog1.OverwritePrompt = True

    ' Set the file name to myText.txt, set the type filter
    ' to text files, and set the initial directory to the 
    ' MyDocuments folder.
    SaveFileDialog1.FileName = "myText"
    ' DefaultExt is only used when "All files" is selected from 
    ' the filter box and no extension is specified by the user.
    SaveFileDialog1.DefaultExt = "txt"
    SaveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
    SaveFileDialog1.InitialDirectory = _
        Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
资料来源:

我建议您阅读更多关于FileName属性的内容,以便找到您要查找的内容:-),希望这能解决您的问题


编辑:将代码更改为VB。对不起,我应该把问题读得更清楚些。今天做得太多了

在调用ShowDialog()之前,请先设置FileName属性。请帮自己一个忙,好好研究一下。以这种方式提出的问题——不费吹灰之力——通常会得到很多反对票。然后再加上你的知识,VB6和VB.NET是不一样的。使用正确的标记我的错误与额外的标记VB6不做
导入…
;这是VB.NET代码。在显示前设置
dlgSave.Filename
属性。这不是VB代码,可能会使任何将其粘贴到代码中的新手感到困惑