0% found this document useful (0 votes)
43 views

Imports Global Partial Class Inherits: System - Io - Form1 System - Windows.Forms - Form

'Required by the Windows Form Designer 'Do not modify it using the code editor. 'Form overrides dispose to clean up the component list.

Uploaded by

rkpaul89
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Imports Global Partial Class Inherits: System - Io - Form1 System - Windows.Forms - Form

'Required by the Windows Form Designer 'Do not modify it using the code editor. 'Form overrides dispose to clean up the component list.

Uploaded by

rkpaul89
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Imports System.io <Global.Microsoft.VisualBasic.CompilerServices.Designer Generated()> _ Partial Class Form1 Inherits System.Windows.Forms.

Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean)

Then

If disposing AndAlso components IsNot Nothing

components.Dispose() End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.MenuStrip1 = New System.Windows.Forms.MenuStrip Me.FileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem Me.OpenToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem Me.SaveToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem Me.SelectFontToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem Me.SelectColorToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem Me.RichTextBox1 = New System.Windows.Forms.RichTextBox Me.Button1 = New System.Windows.Forms.Button Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog Me.FontDialog1 = New System.Windows.Forms.FontDialog

Me.ColorDialog1 = New System.Windows.Forms.ColorDialog Me.MenuStrip1.SuspendLayout() Me.SuspendLayout() ' 'MenuStrip1 ' Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.FileToolStripMenuItem}) Me.MenuStrip1.Location = New System.Drawing.Point(0, 0) Me.MenuStrip1.Name = "MenuStrip1" Me.MenuStrip1.Size = New System.Drawing.Size(405, 24) Me.MenuStrip1.TabIndex = 0 Me.MenuStrip1.Text = "MenuStrip1" ' 'FileToolStripMenuItem ' Me.FileToolStripMenuItem.DropDownItems.AddRange (New System.Windows.Forms.ToolStripItem() {Me.OpenToolStripMenuItem, Me.SaveToolStripMenuItem, Me.SelectFontToolStripMenuItem, Me.SelectColorToolStripMenuItem}) Me.FileToolStripMenuItem.Name = "FileToolStripMenuItem" Me.FileToolStripMenuItem.Size = New System.Drawing.Size(37, 20) Me.FileToolStripMenuItem.Text = "File" ' 'OpenToolStripMenuItem ' Me.OpenToolStripMenuItem.Name = "OpenToolStripMenuItem" Me.OpenToolStripMenuItem.Size = New System.Drawing.Size(152, 22) Me.OpenToolStripMenuItem.Text = "Open" ' 'SaveToolStripMenuItem

' Me.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem" Me.SaveToolStripMenuItem.Size = New System.Drawing.Size(152, 22) Me.SaveToolStripMenuItem.Text = "Save" ' 'SelectFontToolStripMenuItem ' Me.SelectFontToolStripMenuItem.Name = "SelectFontToolStripMenuItem" Me.SelectFontToolStripMenuItem.Size = New System.Drawing.Size(152, 22) Me.SelectFontToolStripMenuItem.Text = "Select Font" ' 'SelectColorToolStripMenuItem ' Me.SelectColorToolStripMenuItem.Name = "SelectColorToolStripMenuItem" Me.SelectColorToolStripMenuItem.Size = New System.Drawing.Size(152, 22) Me.SelectColorToolStripMenuItem.Text = "Select Color" ' 'RichTextBox1 ' Me.RichTextBox1.Location = New System.Drawing.Point(154, 27) Me.RichTextBox1.Name = "RichTextBox1" Me.RichTextBox1.Size = New System.Drawing.Size(227, 176) Me.RichTextBox1.TabIndex = 2 Me.RichTextBox1.Text = "" ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(276, 233) Me.Button1.Name = "Button1"

23)

Me.Button1.Size = New System.Drawing.Size(75,

Me.Button1.TabIndex = 3 Me.Button1.Text = "Clear text" Me.Button1.UseVisualStyleBackColor = True ' 'OpenFileDialog1 ' Me.OpenFileDialog1.FileName = "OpenFileDialog1" ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(405, 262) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.RichTextBox1) Me.Controls.Add(Me.MenuStrip1) Me.Name = "Form1" Me.Text = "Form1" Me.MenuStrip1.ResumeLayout(False) Me.MenuStrip1.PerformLayout() Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip Friend WithEvents FileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem Friend WithEvents OpenToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem Friend WithEvents SaveToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem Friend WithEvents SelectFontToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem

Friend WithEvents SelectColorToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click RichTextBox1.Text = " " End Sub Private FileName As String 'declaring filename that will be selected Dim sr As StreamReader 'streamreader is used to read text Open File Dialog Box Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click Try With OpenFileDialog1 'With statement is used to execute statements using a particular object, here,_ 'OpenFileDialog1 .Filter = "Text files (*.txt)|*.txt|" & "All files|*.*" 'setting filters so that Text files and All Files choice appears in the Files of Type box 'in the dialog

If .ShowDialog() = Windows.Forms.DialogResult.OK Then 'showDialog method makes the dialog box visible at run time FileName = .FileName sr = New StreamReader(.OpenFile) 'using streamreader to read the opened text file RichTextBox1.Text = sr.ReadToEnd() 'displaying text from streamreader in richtextbox End If End With Catch es As Exception MessageBox.Show(es.Message) Finally If Not (sr Is Nothing) Then sr.Close() End If End Try End Sub Save File Dialog Box Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click Dim sw As StreamWriter 'streamwriter is used to write text Try With SaveFileDialog1 .FileName = FileName .Filter = "Text files (*.txt)|*.txt|" & "All files|*.*" If .ShowDialog() = Windows.Forms.DialogResult.OK Then FileName = .FileName sw = New StreamWriter(FileName) 'using streamwriter to write text from richtextbox and saving it sw.Write(RichTextBox1.Text) End If

End With Catch es As Exception MessageBox.Show(es.Message) Finally If Not (sw Is Nothing) Then sw.Close() End If End Try End Sub Font Dialog Box Private Sub SelectFontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectFontToolStripMenuItem.Click Try With FontDialog1 .Font = RichTextBox1.Font 'initializing the dialog box to match the font used in the richtextbox .Color = RichTextBox1.ForeColor 'default color is Black If .ShowDialog = Windows.Forms.DialogResult.OK Then setFont() 'calling a method setFont() to set the selected font and color End If End With Catch es As Exception MessageBox.Show(es.Message) End Try End Sub Private Sub setFont() Try With FontDialog1 RichTextBox1.Font = .Font If .ShowColor Then RichTextBox1.ForeColor = .Color

'setting the color End If End With Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Color Dialog Box Private Sub SelectColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectColorToolStripMenuItem.Click Static CustomColors() As Integer = {RGB(255, 0, 0), RGB(0, 255, 0), RGB(0, 0, 255)} 'initializing CustomColors with an array of integers and putting Red, Green, 'and Blue in the custom colors section Try With ColorDialog1 .Color = RichTextBox1.ForeColor 'initializing the selected color to match the color currently used 'by the richtextbox's foreground color .CustomColors = CustomColors 'filling custom colors on the dialog box with the array declared above If .ShowDialog() = Windows.Forms.DialogResult.OK Then RichTextBox1.ForeColor = .Color CustomColors = .CustomColors 'Storing the custom colors to use again End If ColorDialog1.Reset() 'resetting all colors in the dialog box End With Catch es As Exception MessageBox.Show(es.Message) End Try

End Sub End Class

You might also like