VB.Net by API/System.Windows.Forms/SaveFileDialog
Содержание
SaveFileDialog.CreatePrompt
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
SaveFileDialog.DefaultExt
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
SaveFileDialog.FileName
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
SaveFileDialog.FileOk
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
SaveFileDialog.Filter
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
SaveFileDialog.FilterIndex
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
SaveFileDialog.OverwritePrompt
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
SaveFileDialog.ShowDialog()
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
SaveFileDialog.Title
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