Open, Save, Color, Font and Print Dialog Controls
Imports System.IOPublic Class DialogssPrivate Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickOpenFileDialog1.Title = "Select File to open"OpenFileDialog1.Filter = "Text File|*.txt|All Files|*.*"OpenFileDialog1.FilterIndex = 1OpenFileDialog1.CheckFileExists = TrueOpenFileDialog1.CheckPathExists = TrueOpenFileDialog1.InitialDirectory=My.Computer.FileSystem.SpecialDirectories.MyDocumentsOpenFileDialog1.Multiselect = FalseOpenFileDialog1.ShowHelp = TrueDim rfile As StreamReaderIf OpenFileDialog1.ShowDialog = MsgBoxResult.OK Thenrfile = New StreamReader(OpenFileDialog1.FileName)Me.TextBox1.Text = rfile.ReadToEndEnd IfEnd SubPrivate Sub Button2_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickSaveFileDialog1.Title = "Save File"SaveFileDialog1.Filter = "Text Files|*.txt|All Files|*.*"SaveFileDialog1.AddExtension = TrueSaveFileDialog1.DefaultExt = "txt"Dim wfile As StreamWriterIf SaveFileDialog1.ShowDialog = MsgBoxResult.Ok Thenwfile = New StreamWriter(SaveFileDialog1.FileName)wfile.Write (Me.TextBox1.Text)wfile.Close ()End IfEnd SubPrivate Sub Button3_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickColorDialog1.AllowFullOpen = TrueColorDialog1.FullOpen = TrueIf ColorDialog1.ShowDialog = MsgBoxResult.Ok ThenMe.TextBox1.ForeColor = ColorDialog1.ColorEnd IfEnd SubPrivate Sub Button4_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickFontDialog1.ShowEffects = TrueFontDialog1.ShowApply = TrueIf FontDialog1.ShowDialog = MsgBoxResult.Ok ThenMe.TextBox1.Font = FontDialog1.FontEnd IfEnd SubPrivate Sub Button5_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickPrintDialog1.AllowPrintToFile = TruePrintDialog1.AllowSelection = TrueDim pd As New Printing.PrintDocumentPrintDialog1.Document = New Printing.PrintDocumentIf PrintDialog1.ShowDialog = MsgBoxResult.Ok Thenpd.Print()End IfEnd SubEnd Class
No comments:
Post a Comment