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对话框操作实例(三)

保存对话框

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对话框操作实例(三)vb.net对话框操作实例(三)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对话框操作实例(三)
  • VB6源码实现超高精度计时器(精确到微秒)
  • vb.net中的循环语句
  • java生成复杂excel文件
  • 在windows中怎样安装qt
  • 怎样辨别小儿便秘和巨结肠
  • 热门搜索
    旅游宣传广告 绵山旅游 河北承德旅游景点 广州从化旅游 巴厘岛旅游地图 太原旅游团 中国旅游资讯 新西兰旅游要多少钱 郊区旅游 甘南州旅游局