Imports System.IO
Public Class EditorNet
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub
Private Sub CorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CorToolStripMenuItem.Click
ColorDialog1.ShowDialog()
Me.ColorDialog1.Color = Me.RichTextBox1.ForeColor
If Me.ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.RichTextBox1.ForeColor = Me.ColorDialog1.Color
End If
End Sub
Private Sub AcercaEditorNetToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
AcercaEditorNetToolStripMenuItem.Click
Acerca_EditorNet.ShowDialog()
End Sub
Private Sub AnularToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles AnularToolStripMenuItem.Click
RichTextBox1.Undo()
End Sub
Private Sub AnularToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs)
End Sub
Private Sub NovoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles NovoToolStripMenuItem.Click
Call Novo()
End Sub
Private Sub Novo()
If RichTextBox1.Text = " " Then
RichTextBox1.Clear()
RichTextBox1.Focus()
Return
Else
Dim res As DialogResult
res = MessageBox.Show("O documento foi alterado. Deseja guardar?",
"Guardar- EditorNet", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
If res = Windows.Forms.DialogResult.No Then
RichTextBox1.Clear()
RichTextBox1.Focus()
Return
Else
Call guardar()
End If
End If
End Sub
Private Sub GuardarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles GuardarToolStripMenuItem.Click
If Me.SaveFileDialog1.CheckFileExists = True Then
File.WriteAllText(Me.SaveFileDialog1.FileName, Me.RichTextBox1.Text)
MsgBox("Documento Guardado em " & Me.SaveFileDialog1.FileName.ToString)
Else
Call guardar()
End If
End Sub
Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SaveToolStripButton.Click
Call guardar()
End Sub
Private Sub GuardarComoToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles GuardarComoToolStripMenuItem.Click
Call guardar()
End Sub
Private Sub guardar()
Try
Me.SaveFileDialog1().Title = "Guardar..."
Me.SaveFileDialog1.DefaultExt = "txt"
Me.SaveFileDialog1.Filter = "Ficheiros de Texto (*.txt)|*.txt"
Me.SaveFileDialog1.DefaultExt = "txt"
If Me.SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
File.WriteAllText(Me.SaveFileDialog1.FileName, Me.RichTextBox1.Text)
MsgBox("Documento Guardado em " &
Me.SaveFileDialog1.FileName.ToString)
Me.SaveFileDialog1.CheckFileExists = True
End If
Catch ex As Exception
MsgBox("Ocorreu um Erro ao Guardar o Documento")
End Try
End Sub
Private Sub AbrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles AbrirToolStripMenuItem.Click
Call Abrir()
End Sub
Private Sub Abrir()
Try
Me.OpenFileDialog1.Title = "Abrir..."
Me.OpenFileDialog1.FileName = ""
Me.OpenFileDialog1.Filter = "ficheiros de
texto(*.txt)|*.txt|Todos(*.*)|*.*"
Me.OpenFileDialog1.FilterIndex = 1
If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.RichTextBox1.Text = File.ReadAllText(Me.OpenFileDialog1.FileName)
End If
Catch ex As Exception
MsgBox("Ocorreu um Erro ao Abrir o Documento")
End Try
End Sub
Private Sub OpenToolStripButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OpenToolStripButton.Click
Call Abrir()
End Sub
Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripButton5.Click
Dim b As Boolean = ToolStripButton5.Checked
Dim nome_fonte As String = RichTextBox1.Font.Name
Dim tamanho_fonte As Single = RichTextBox1.Font.Size
If b = True Then
RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte,
FontStyle.Italic)
b = False
Else
RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte,
FontStyle.Regular)
b = True
End If
End Sub
Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripButton4.Click
Dim b As Boolean = ToolStripButton4.Checked
Dim nome_fonte As String = RichTextBox1.Font.Name
Dim tamanho_fonte As Single = RichTextBox1.Font.Size
If b = True Then
RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte,
FontStyle.Bold)
b = False
Else
RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte,
FontStyle.Regular)
b = True
End If
End Sub
Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ToolStripButton6.Click
Dim b As Boolean = ToolStripButton6.Checked
Dim nome_fonte As String = RichTextBox1.Font.Name
Dim tamanho_fonte As Single = RichTextBox1.Font.Size
If b = True Then
RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte,
FontStyle.Underline)
b = False
Else
RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte,
FontStyle.Regular)
b = True
End If
End Sub
Private Sub RichTextBox1_TextChanged_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RichTextBox1.TextChanged
End Sub
Private Sub ConfigurarPáginaToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ConfigurarPáginaToolStripMenuItem.Click
PageSetupDialog1.ShowDialog()
End Sub
Private Sub PréVisualizarToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles PréVisualizarToolStripMenuItem.Click
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub ImprimirRápidoToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ImprimirRápidoToolStripMenuItem.Click
PrintDocument1.Print()
End Sub
Private Sub ImprimirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ImprimirToolStripMenuItem.Click
PrintDialog1.Document = PrintDocument1
If PrintDialog1.ShowDialog() = DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
Private Sub PrintToolStripButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PrintToolStripButton.Click
PrintDocument1.Print()
End Sub
Private Sub SairToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles SairToolStripMenuItem.Click
End
End Sub
Private Sub SubstituirToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles SubstituirToolStripMenuItem.Click
If RichTextBox1.TextLength > 0 Then
Substituir.Show()
Else
MsgBox("Não há texto para substituir!")
End If
End Sub
Private Sub CortarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CortarToolStripMenuItem.Click
RichTextBox1.Cut()
End Sub
Private Sub CopiarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CopiarToolStripMenuItem.Click
RichTextBox1.Copy()
MessageBox.Show("Texto copiado com sucesso")
End Sub
Private Sub ColarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ColarToolStripMenuItem.Click
RichTextBox1.Paste()
End Sub
Private Sub TipoDeLetraToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TipoDeLetraToolStripMenuItem.Click
Me.FontDialog1.ShowColor = True
If Me.FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.RichTextBox1.Font = Me.FontDialog1.Font
End If
End Sub
Private Sub SelecionarTudoToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles SelecionarTudoToolStripMenuItem.Click
RichTextBox1.SelectAll()
End Sub
Private Sub NewToolStripButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NewToolStripButton.Click
Call Novo()
End Sub
Private Sub PasteToolStripButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PasteToolStripButton.Click
RichTextBox1.Paste()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim g As Graphics = e.Graphics
Dim brush As New SolidBrush(RichTextBox1.ForeColor)
Dim mensagem As String = RichTextBox1.Text
Dim fonte As New Font(RichTextBox1.Font.Name, RichTextBox1.Font.Size,
System.Drawing.GraphicsUnit.Point)
g.DrawString(mensagem, fonte, brush, 100, 100)
e.Graphics.PageUnit = GraphicsUnit.Inch
End Sub
End Class

Código Editor Net

  • 1.
    Imports System.IO Public ClassEditorNet Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub CorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CorToolStripMenuItem.Click ColorDialog1.ShowDialog() Me.ColorDialog1.Color = Me.RichTextBox1.ForeColor If Me.ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then Me.RichTextBox1.ForeColor = Me.ColorDialog1.Color End If End Sub Private Sub AcercaEditorNetToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AcercaEditorNetToolStripMenuItem.Click Acerca_EditorNet.ShowDialog() End Sub Private Sub AnularToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AnularToolStripMenuItem.Click RichTextBox1.Undo() End Sub Private Sub AnularToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub NovoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NovoToolStripMenuItem.Click Call Novo() End Sub Private Sub Novo() If RichTextBox1.Text = " " Then RichTextBox1.Clear() RichTextBox1.Focus() Return Else Dim res As DialogResult res = MessageBox.Show("O documento foi alterado. Deseja guardar?", "Guardar- EditorNet", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) If res = Windows.Forms.DialogResult.No Then RichTextBox1.Clear() RichTextBox1.Focus() Return Else Call guardar() End If End If
  • 2.
    End Sub Private SubGuardarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GuardarToolStripMenuItem.Click If Me.SaveFileDialog1.CheckFileExists = True Then File.WriteAllText(Me.SaveFileDialog1.FileName, Me.RichTextBox1.Text) MsgBox("Documento Guardado em " & Me.SaveFileDialog1.FileName.ToString) Else Call guardar() End If End Sub Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click Call guardar() End Sub Private Sub GuardarComoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GuardarComoToolStripMenuItem.Click Call guardar() End Sub Private Sub guardar() Try Me.SaveFileDialog1().Title = "Guardar..." Me.SaveFileDialog1.DefaultExt = "txt" Me.SaveFileDialog1.Filter = "Ficheiros de Texto (*.txt)|*.txt" Me.SaveFileDialog1.DefaultExt = "txt" If Me.SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then File.WriteAllText(Me.SaveFileDialog1.FileName, Me.RichTextBox1.Text) MsgBox("Documento Guardado em " & Me.SaveFileDialog1.FileName.ToString) Me.SaveFileDialog1.CheckFileExists = True End If Catch ex As Exception MsgBox("Ocorreu um Erro ao Guardar o Documento") End Try End Sub Private Sub AbrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbrirToolStripMenuItem.Click Call Abrir() End Sub Private Sub Abrir() Try Me.OpenFileDialog1.Title = "Abrir..." Me.OpenFileDialog1.FileName = "" Me.OpenFileDialog1.Filter = "ficheiros de texto(*.txt)|*.txt|Todos(*.*)|*.*" Me.OpenFileDialog1.FilterIndex = 1 If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Me.RichTextBox1.Text = File.ReadAllText(Me.OpenFileDialog1.FileName) End If Catch ex As Exception
  • 3.
    MsgBox("Ocorreu um Erroao Abrir o Documento") End Try End Sub Private Sub OpenToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripButton.Click Call Abrir() End Sub Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click Dim b As Boolean = ToolStripButton5.Checked Dim nome_fonte As String = RichTextBox1.Font.Name Dim tamanho_fonte As Single = RichTextBox1.Font.Size If b = True Then RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte, FontStyle.Italic) b = False Else RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte, FontStyle.Regular) b = True End If End Sub Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click Dim b As Boolean = ToolStripButton4.Checked Dim nome_fonte As String = RichTextBox1.Font.Name Dim tamanho_fonte As Single = RichTextBox1.Font.Size If b = True Then RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte, FontStyle.Bold) b = False Else RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte, FontStyle.Regular) b = True End If End Sub Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click Dim b As Boolean = ToolStripButton6.Checked Dim nome_fonte As String = RichTextBox1.Font.Name Dim tamanho_fonte As Single = RichTextBox1.Font.Size If b = True Then RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte, FontStyle.Underline) b = False Else RichTextBox1.SelectionFont = New Font(nome_fonte, tamanho_fonte, FontStyle.Regular) b = True End If End Sub
  • 4.
    Private Sub RichTextBox1_TextChanged_1(ByValsender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged End Sub Private Sub ConfigurarPáginaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigurarPáginaToolStripMenuItem.Click PageSetupDialog1.ShowDialog() End Sub Private Sub PréVisualizarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PréVisualizarToolStripMenuItem.Click PrintPreviewDialog1.ShowDialog() End Sub Private Sub ImprimirRápidoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImprimirRápidoToolStripMenuItem.Click PrintDocument1.Print() End Sub Private Sub ImprimirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImprimirToolStripMenuItem.Click PrintDialog1.Document = PrintDocument1 If PrintDialog1.ShowDialog() = DialogResult.OK Then PrintDocument1.Print() End If End Sub Private Sub PrintToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripButton.Click PrintDocument1.Print() End Sub Private Sub SairToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SairToolStripMenuItem.Click End End Sub Private Sub SubstituirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubstituirToolStripMenuItem.Click If RichTextBox1.TextLength > 0 Then Substituir.Show() Else MsgBox("Não há texto para substituir!") End If End Sub Private Sub CortarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CortarToolStripMenuItem.Click RichTextBox1.Cut() End Sub Private Sub CopiarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopiarToolStripMenuItem.Click RichTextBox1.Copy() MessageBox.Show("Texto copiado com sucesso") End Sub
  • 5.
    Private Sub ColarToolStripMenuItem_Click(ByValsender As System.Object, ByVal e As System.EventArgs) Handles ColarToolStripMenuItem.Click RichTextBox1.Paste() End Sub Private Sub TipoDeLetraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TipoDeLetraToolStripMenuItem.Click Me.FontDialog1.ShowColor = True If Me.FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Me.RichTextBox1.Font = Me.FontDialog1.Font End If End Sub Private Sub SelecionarTudoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelecionarTudoToolStripMenuItem.Click RichTextBox1.SelectAll() End Sub Private Sub NewToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripButton.Click Call Novo() End Sub Private Sub PasteToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripButton.Click RichTextBox1.Paste() End Sub Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage Dim g As Graphics = e.Graphics Dim brush As New SolidBrush(RichTextBox1.ForeColor) Dim mensagem As String = RichTextBox1.Text Dim fonte As New Font(RichTextBox1.Font.Name, RichTextBox1.Font.Size, System.Drawing.GraphicsUnit.Point) g.DrawString(mensagem, fonte, brush, 100, 100) e.Graphics.PageUnit = GraphicsUnit.Inch End Sub End Class