手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

vb.net对话框操作实例(三)

时间:2024-10-12 06:25:28

Creating a Save dialog that enables you to save filesCreating a Font dialog that enables you to apply the selected font to textCreating a Color dialog that enables you to define and select custom colorsCreating a Print dialog that prints text from your applicationCreating a Browse dialog that enables you to browse for folders

工具/原料

visual studio 2015

打开对话框

1、 Private Sub btnOpen_Click(sender As Object, e As EventArgs) Handles btnOpen.Cli艘早祓胂ck 'Set the Open dialog properties OpenFileDialog1.Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*" OpenFileDialog1.FilterIndex = 1 OpenFileDialog1.Title = "Demo Open File Dialog" 'Show the Open dialog if the user clicks the Open button, 'load the file If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Try 'Save the file path and name strFileName = OpenFileDialog1.FileName Dim fileContents As String fileContents = My.Computer.FileSystem.ReadAllText(strFileName) 'Display the file contents in the text box txtFile.Text = fileContents Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If End Sub

vb.net对话框操作实例(三)
vb.net对话框操作实例(三)

保存对话框

1、Private Sub bthSave_Click(sender As Object, e As EventArgs) Handles bthSave.Click 'Set the Save dialog properties With SaveFileDialog1 .DefaultExt = "txt" .FileName = strFileName .Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*" .FilterIndex = 1 .OverwritePrompt = True .Title = "Demo Save File Dialog" End With 'Show the Save dialog and if the user clicks the Save button, 'save the file If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Try 'Save the file path and name strFileName = SaveFileDialog1.FileName My.Computer.FileSystem.WriteAllText(strFileName, txtFile.Text, False) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If End Sub

vb.net对话框操作实例(三)

字体对话框

1、 Private Sub btnFont_Click(sender As Object, e As EventArgs) Handles btnFont.Click 'Set the Font dialog properties FontDialog1.ShowColor = True 'Show the Font dialog and if the user clicks the OK button, 'update the font and color in the text box If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then txtFile.Font = FontDialog1.Font txtFile.ForeColor = FontDialog1.Color End If End Sub

vb.net对话框操作实例(三)
vb.net对话框操作实例(三)

颜色对话框

1、 Private Sub btmColor_Click(sender As Object, e As EventArgs) Handles btmColor.Click 'Show the Color dialog and if the user clicks the OK button, 'update the background color of the form If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Me.BackColor = ColorDialog1.Color End If End Sub

vb.net对话框操作实例(三)
vb.net对话框操作实例(三)

打印对话框

1、 Private Sub btnPrint_Click(sender As Object, e As EventArgs) Hand造婷用痃les btnPrint.Click 'Instantiate a new instance of the PrintDocument DialogsPrintDocument = New PrintDocument 'Set the PrintDialog properties With PrintDialog1 .AllowCurrentPage = False .AllowPrintToFile = False .AllowSelection = False .AllowSomePages = False .Document = DialogsPrintDocument .PrinterSettings.DefaultPageSettings.Margins.Top = 25 .PrinterSettings.DefaultPageSettings.Margins.Bottom = 25 .PrinterSettings.DefaultPageSettings.Margins.Left = 25 .PrinterSettings.DefaultPageSettings.Margins.Right = 25 End With If PrintDialog1.ShowDialog = DialogResult.OK Then 'Set the selected printer settings in the PrintDocument DialogsPrintDocument.PrinterSettings = PrintDialog1.PrinterSettings 'Get the print data strPrintRecord = txtFile.Text 'Invoke the Print method on the PrintDocument DialogsPrintDocument.Print() End If End Sub

vb.net对话框操作实例(三)

浏览对话框

1、 Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click 'Set the FolderBrowser dialog properties With FolderBrowserDialog1 .Description = "Select a backup folder" .RootFolder = Environment.SpecialFolder.MyComputer .ShowNewFolderButton = False End With 'Show the FolderBrowser dialog and if the user clicks the 'OK button, display the selected folder If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then txtFile.Text = FolderBrowserDialog1.SelectedPath End If End Sub

vb.net对话框操作实例(三)
© 手抄报圈