VB.Net by API/System.Windows.Forms/SaveFileDialog

Материал из VB Эксперт
Перейти к: навигация, поиск

SaveFileDialog.CreatePrompt

<source lang="vbnet"> Imports System.Windows.Forms public class FileOpenDialogFilter

  public Shared Sub Main
       Dim saveFileDialog1 As System.Windows.Forms.SaveFileDialog
       saveFileDialog1 = New System.Windows.Forms.SaveFileDialog()
       saveFileDialog1.CreatePrompt = True
       saveFileDialog1.FileName = "doc1"
       saveFileDialog1.Filter = "Word (*.doc) |*.doc;*.rtf|(*.txt) |*.txt|(*.*) |*.*"
       If saveFileDialog1.ShowDialog() = DialogResult.OK Then
           Console.WriteLine(saveFileDialog1.FileName)
       End If
  End Sub

End class


 </source>


SaveFileDialog.DefaultExt

<source lang="vbnet">

Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.IO Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
       "Declare a SaveFileDialog object
       Dim objSaveFileDialog As New SaveFileDialog
       "Set the Save dialog properties
       With objSaveFileDialog
           .DefaultExt = "txt"
           .FileName = "Test Document"
           .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
           .FilterIndex = 1
           .OverwritePrompt = True
           .Title = "Demo Save File Dialog"
       End With
       If objSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
           Try
               Dim filePath As String
               filePath = System.IO.Path.rubine( _
                   My.ruputer.FileSystem.SpecialDirectories.MyDocuments, _
                   objSaveFileDialog.FileName)
               My.ruputer.FileSystem.WriteAllText(filePath, "C:\\a.txt", False)
           Catch fileException As Exception
               Throw fileException
           End Try
       End If
       "Clean up
       objSaveFileDialog.Dispose()
       objSaveFileDialog = Nothing
   End Sub

End Class


 </source>


SaveFileDialog.FileName

<source lang="vbnet">

Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.IO Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
       "Declare a SaveFileDialog object
       Dim objSaveFileDialog As New SaveFileDialog
       "Set the Save dialog properties
       With objSaveFileDialog
           .DefaultExt = "txt"
           .FileName = "Test Document"
           .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
           .FilterIndex = 1
           .OverwritePrompt = True
           .Title = "Demo Save File Dialog"
       End With
       If objSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
           Try
               Dim filePath As String
               filePath = System.IO.Path.rubine( _
                   My.ruputer.FileSystem.SpecialDirectories.MyDocuments, _
                   objSaveFileDialog.FileName)
               My.ruputer.FileSystem.WriteAllText(filePath, "C:\\a.txt", False)
           Catch fileException As Exception
               Throw fileException
           End Try
       End If
       "Clean up
       objSaveFileDialog.Dispose()
       objSaveFileDialog = Nothing
   End Sub

End Class


 </source>


SaveFileDialog.FileOk

<source lang="vbnet">

Imports System Imports System.Data Imports System.Windows.Forms Imports System.Drawing Imports System.Diagnostics Imports System.Drawing.Printing Imports System.ruponentModel

Public Class MainClass

   Shared Dim  WithEvents dlgSaveData As System.Windows.Forms.SaveFileDialog
   
   Shared Sub Main()
       dlgSaveData = New System.Windows.Forms.SaveFileDialog
       If dlgSaveData.ShowDialog() = Windows.Forms.DialogResult.OK Then
           MessageBox.Show(dlgSaveData.FileName)
       End If
   End Sub
   
   Shared Private Sub dlgSaveData_FileOk(ByVal sender As Object, _
    ByVal e As System.ruponentModel.CancelEventArgs) Handles dlgSaveData.FileOk
       
       
       If Not dlgSaveData.FileName.EndsWith(".dat") Then
           MsgBox("File " & dlgSaveData.FileName & _
               " is not a .dat file", _
               MsgBoxStyle.Exclamation, _
               "Invalid File Type")
           e.Cancel = True
       End If
   End Sub    

End Class


 </source>


SaveFileDialog.Filter

<source lang="vbnet">

Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.IO Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
       "Declare a SaveFileDialog object
       Dim objSaveFileDialog As New SaveFileDialog
       "Set the Save dialog properties
       With objSaveFileDialog
           .DefaultExt = "txt"
           .FileName = "Test Document"
           .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
           .FilterIndex = 1
           .OverwritePrompt = True
           .Title = "Demo Save File Dialog"
       End With
       If objSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
           Try
               Dim filePath As String
               filePath = System.IO.Path.rubine( _
                   My.ruputer.FileSystem.SpecialDirectories.MyDocuments, _
                   objSaveFileDialog.FileName)
               My.ruputer.FileSystem.WriteAllText(filePath, "C:\\a.txt", False)
           Catch fileException As Exception
               Throw fileException
           End Try
       End If
       "Clean up
       objSaveFileDialog.Dispose()
       objSaveFileDialog = Nothing
   End Sub

End Class


 </source>


SaveFileDialog.FilterIndex

<source lang="vbnet">

Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.IO Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
       "Declare a SaveFileDialog object
       Dim objSaveFileDialog As New SaveFileDialog
       "Set the Save dialog properties
       With objSaveFileDialog
           .DefaultExt = "txt"
           .FileName = "Test Document"
           .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
           .FilterIndex = 1
           .OverwritePrompt = True
           .Title = "Demo Save File Dialog"
       End With
       If objSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
           Try
               Dim filePath As String
               filePath = System.IO.Path.rubine( _
                   My.ruputer.FileSystem.SpecialDirectories.MyDocuments, _
                   objSaveFileDialog.FileName)
               My.ruputer.FileSystem.WriteAllText(filePath, "C:\\a.txt", False)
           Catch fileException As Exception
               Throw fileException
           End Try
       End If
       "Clean up
       objSaveFileDialog.Dispose()
       objSaveFileDialog = Nothing
   End Sub

End Class


 </source>


SaveFileDialog.OverwritePrompt

<source lang="vbnet">

Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.IO Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
       "Declare a SaveFileDialog object
       Dim objSaveFileDialog As New SaveFileDialog
       "Set the Save dialog properties
       With objSaveFileDialog
           .DefaultExt = "txt"
           .FileName = "Test Document"
           .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
           .FilterIndex = 1
           .OverwritePrompt = True
           .Title = "Demo Save File Dialog"
       End With
       If objSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
           Try
               Dim filePath As String
               filePath = System.IO.Path.rubine( _
                   My.ruputer.FileSystem.SpecialDirectories.MyDocuments, _
                   objSaveFileDialog.FileName)
               My.ruputer.FileSystem.WriteAllText(filePath, "C:\\a.txt", False)
           Catch fileException As Exception
               Throw fileException
           End Try
       End If
       "Clean up
       objSaveFileDialog.Dispose()
       objSaveFileDialog = Nothing
   End Sub

End Class


 </source>


SaveFileDialog.ShowDialog()

<source lang="vbnet"> Imports System Imports System.Data Imports System.Windows.Forms Imports System.Drawing Imports System.Diagnostics Imports System.Drawing.Printing Imports System.ruponentModel

Public Class MainClass

   Shared Dim  WithEvents dlgSaveData As System.Windows.Forms.SaveFileDialog
   
   Shared Sub Main()
       dlgSaveData = New System.Windows.Forms.SaveFileDialog
       If dlgSaveData.ShowDialog() = Windows.Forms.DialogResult.OK Then
           MessageBox.Show(dlgSaveData.FileName)
       End If
   End Sub
   
   Shared Private Sub dlgSaveData_FileOk(ByVal sender As Object, _
    ByVal e As System.ruponentModel.CancelEventArgs) Handles dlgSaveData.FileOk
       
       
       If Not dlgSaveData.FileName.EndsWith(".dat") Then
           MsgBox("File " & dlgSaveData.FileName & _
               " is not a .dat file", _
               MsgBoxStyle.Exclamation, _
               "Invalid File Type")
           e.Cancel = True
       End If
   End Sub    

End Class


 </source>


SaveFileDialog.Title

<source lang="vbnet">

Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.IO Imports System.Drawing.Printing

Public Class MainClass

   Shared Sub Main()
       "Declare a SaveFileDialog object
       Dim objSaveFileDialog As New SaveFileDialog
       "Set the Save dialog properties
       With objSaveFileDialog
           .DefaultExt = "txt"
           .FileName = "Test Document"
           .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
           .FilterIndex = 1
           .OverwritePrompt = True
           .Title = "Demo Save File Dialog"
       End With
       If objSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
           Try
               Dim filePath As String
               filePath = System.IO.Path.rubine( _
                   My.ruputer.FileSystem.SpecialDirectories.MyDocuments, _
                   objSaveFileDialog.FileName)
               My.ruputer.FileSystem.WriteAllText(filePath, "C:\\a.txt", False)
           Catch fileException As Exception
               Throw fileException
           End Try
       End If
       "Clean up
       objSaveFileDialog.Dispose()
       objSaveFileDialog = Nothing
   End Sub

End Class


 </source>