05-20-2011, 08:50 PM
Keep Updated on this channel as I will release newer versions in later posts throughout this thread! First thread can't be upadted anymore becuase i've maxed out on the character limit for this first post.
Part 1
Description: Notepad Plus + is a project that I created originally to have my own notepad application that I could use as an alternative to the original Notepad that comes as a default application on Windows. I created it so that it's fairly customizable for the user, and it looks nice, which is an added bonus. It's really designed to fit the users needs. Later on with this project I plan on making saveable settings for the user so that everything that gets customized with my application will be a set value for future use.
File Information:
- Filetype: Application
- Description Notepad Plus +
- Filesize: 752Kb
- Original MD5: E992BB7D162FE05039E1F0B4D17B9ED1
GUI Class Theme: (To use: Add a new class to the project, delete all of the text within the class, and replace it with all of this code. After you have done that, save the class, and go to build. You should now see the theme in your toolbox. [Note: This is a custom class that I created myself.])
Code:
Imports System.Drawing.Drawing2D
Class Pigment
Private _Name As String = "Pigment"
Property Name() As String
Get
Return _Name
End Get
Set(ByVal v As String)
_Name = v
End Set
End Property
Private _Value As Color = Color.Black
Public Property Value() As Color
Get
Return _Value
End Get
Set(ByVal value As Color)
_Value = value
End Set
End Property
Sub New()
End Sub
Sub New(ByVal n As String, ByVal v As Color)
Name = n
Value = v
End Sub
Sub New(ByVal n As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
Name = n
Value = Color.FromArgb(a, r, g, b)
End Sub
Sub New(ByVal n As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
Name = n
Value = Color.FromArgb(r, g, b)
End Sub
End Class
Class FTheme
Inherits ContainerControl
Private _Resizeable As Boolean = True
Public Property Resizeable() As Boolean
Get
Return _Resizeable
End Get
Set(ByVal value As Boolean)
_Resizeable = value
End Set
End Property
Sub New()
SetStyle(DirectCast(8198, ControlStyles), True)
C = New Pigment() { _
New Pigment("Border", Color.Black), _
New Pigment("Frame", 5, 5, 5), _
New Pigment("Border Highlight", 15, 200, 255, 255), _
New Pigment("Side Highlight", 6, 190, 255, 255), _
New Pigment("Shine", 20, 200, 255, 255), _
New Pigment("Shadow", 38, 38, 40), _
New Pigment("Backcolor", 15, 15, 15), _
New Pigment("Transparency", Color.Fuchsia) _
}
End Sub
Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
Dock = DockStyle.Fill
If TypeOf Parent Is Form Then DirectCast(Parent, Form).FormBorderStyle = FormBorderStyle.None
Colors = C
MyBase.OnHandleCreated(e)
End Sub
Const Count As Byte = 8
Private C As Pigment()
Public Property Colors() As Pigment()
Get
Return C
End Get
Set(ByVal v As Pigment())
If v.Length <> Count Then Throw New IndexOutOfRangeException
P1 = New Pen(v(0).Value)
P2 = New Pen(v(2).Value)
B1 = New SolidBrush(v(6).Value)
B2 = New SolidBrush(v(7).Value)
If Parent IsNot Nothing Then
Parent.BackColor = v(6).Value
If TypeOf Parent Is Form Then DirectCast(Parent, Form).TransparencyKey = v(7).Value
End If
CB = New ColorBlend
CB.Colors = New Color() {Color.Transparent, v(4).Value, Color.Transparent}
CB.Positions = New Single() {0, 0.5, 1}
C = v
Invalidate()
End Set
End Property
Private P1, P2, P3 As Pen
Private B1, B2 As SolidBrush, B3, B4 As LinearGradientBrush
Private R1, R2 As Rectangle
Private CB As ColorBlend
Private G As Graphics, B As Bitmap
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
B = New Bitmap(Width, Height)
G = Graphics.FromImage(B)
G.Clear(C(1).Value)
G.DrawRectangle(P2, New Rectangle(1, 1, Width - 3, Height - 3))
G.DrawRectangle(P2, New Rectangle(12, 40, Width - 24, Height - 52))
R1 = New Rectangle(1, 0, 15, Height)
B3 = New LinearGradientBrush(R1, C(3).Value, Color.Transparent, 90.0F)
G.FillRectangle(B3, R1)
G.FillRectangle(B3, New Rectangle(Width - 16, 0, 15, Height))
G.FillRectangle(B1, New Rectangle(13, 41, Width - 26, Height - 54))
R2 = New Rectangle(0, 2, Width, 2)
B4 = New LinearGradientBrush(R2, Color.Empty, Color.Empty, 0)
B4.InterpolationColors = CB
G.FillRectangle(B4, R2)
G.DrawRectangle(P1, New Rectangle(13, 41, Width - 26, Height - 54))
G.DrawRectangle(P1, New Rectangle(0, 0, Width - 1, Height - 1))
G.FillRectangle(B2, New Rectangle(0, 0, 2, 2))
G.FillRectangle(B2, New Rectangle(Width - 2, 0, 2, 2))
G.FillRectangle(B2, New Rectangle(Width - 2, Height - 2, 2, 2))
G.FillRectangle(B2, New Rectangle(0, Height - 2, 2, 2))
B.SetPixel(1, 1, Color.Black)
B.SetPixel(Width - 2, 1, Color.Black)
B.SetPixel(Width - 2, Height - 2, Color.Black)
B.SetPixel(1, Height - 2, Color.Black)
e.Graphics.DrawImage(B, 0, 0)
B3.Dispose()
B4.Dispose()
G.Dispose()
B.Dispose()
End Sub
Enum Direction As Integer
NONE = 0
LEFT = 10
RIGHT = 11
TOP = 12
TOPLEFT = 13
TOPRIGHT = 14
BOTTOM = 15
BOTTOMLEFT = 16
BOTTOMRIGHT = 17
End Enum
Private Current As Direction
Sub SetCurrent()
Dim T As Point = PointToClient(MousePosition)
If T.X < 7 And T.Y < 7 Then
Current = Direction.TOPLEFT
Cursor = Cursors.SizeNWSE
ElseIf T.X < 7 And T.Y > Height - 7 Then
Current = Direction.BOTTOMLEFT
Cursor = Cursors.SizeNESW
ElseIf T.X > Width - 7 And T.Y > Height - 7 Then
Current = Direction.BOTTOMRIGHT
Cursor = Cursors.SizeNWSE
ElseIf T.X > Width - 7 And T.Y < 7 Then
Current = Direction.TOPRIGHT
Cursor = Cursors.SizeNESW
ElseIf T.X < 7 Then
Current = Direction.LEFT
Cursor = Cursors.SizeWE
ElseIf T.X > Width - 7 Then
Current = Direction.RIGHT
Cursor = Cursors.SizeWE
ElseIf T.Y < 7 Then
Current = Direction.TOP
Cursor = Cursors.SizeNS
ElseIf T.Y > Height - 7 Then
Current = Direction.BOTTOM
Cursor = Cursors.SizeNS
Else
Current = Direction.NONE
Cursor = Cursors.Default
End If
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
If e.Button = MouseButtons.Left Then
If TypeOf Parent Is Form Then
If DirectCast(Parent, Form).WindowState = FormWindowState.Maximized Then Return
End If
If Drag.Contains(e.Location) Then
Capture = False
DefWndProc(Message.Create(Parent.Handle, 161, New IntPtr(2), Nothing))
Else
If Current <> Direction.NONE And _Resizeable Then
Capture = False
DefWndProc(Message.Create(Parent.Handle, 161, New IntPtr(Current), Nothing))
End If
End If
End If
MyBase.OnMouseDown(e)
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
If _Resizeable Then SetCurrent()
MyBase.OnMouseMove(e)
End Sub
Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)
Invalidate()
MyBase.OnSizeChanged(e)
End Sub
Private ReadOnly Property Drag() As Rectangle
Get
Return New Rectangle(7, 7, Width - 14, 35)
End Get
End Property
End Class
Class FButton
Inherits Control
Private Shadow_ As Boolean = True
Public Property Shadow() As Boolean
Get
Return Shadow_
End Get
Set(ByVal value As Boolean)
Shadow_ = value
Invalidate()
End Set
End Property
Sub New()
SetStyle(DirectCast(8198, ControlStyles), True)
Colors = New Pigment() {New Pigment("Border", 150, 150, 150), New Pigment("Backcolor", 10, 10, 10), _
New Pigment("Highlight", 150, 150, 160), New Pigment("Gradient1", 100, 100, 100), _
New Pigment("Gradient2", 50, 50, 50), New Pigment("Text Color", Color.White), _
New Pigment("Text Shadow", 30, 0, 0, 0)}
Font = New Font("Verdana", 9)
End Sub
Const Count As Byte = 7
Private C As Pigment()
Public Property Colors() As Pigment()
Get
Return C
End Get
Set(ByVal v As Pigment())
If v.Length <> Count Then Throw New IndexOutOfRangeException
P1 = New Pen(v(0).Value)
P2 = New Pen(v(2).Value)
B1 = New SolidBrush(v(6).Value)
B2 = New SolidBrush(v(5).Value)
C = v
Invalidate()
End Set
End Property
Private P1, P2 As Pen
Private B1, B2 As SolidBrush, B3 As LinearGradientBrush
Private SZ As Size, PT As Point
Private G As Graphics, B As Bitmap
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
B = New Bitmap(Width, Height)
G = Graphics.FromImage(B)
If Down Then
B3 = New LinearGradientBrush(ClientRectangle, C(4).Value, C(3).Value, 90.0F)
Else
B3 = New LinearGradientBrush(ClientRectangle, C(3).Value, C(4).Value, 90.0F)
End If
G.FillRectangle(B3, ClientRectangle)
If Not String.IsNullOrEmpty(Text) Then
SZ = G.MeasureString(Text, Font).ToSize
PT = New Point(CInt(Width / 2 - SZ.Width / 2), CInt(Height / 2 - SZ.Height / 2))
If Shadow_ Then G.DrawString(Text, Font, B1, PT.X + 1, PT.Y + 1)
G.DrawString(Text, Font, B2, PT)
End If
G.DrawRectangle(P1, New Rectangle(0, 0, Width - 1, Height - 1))
G.DrawRectangle(P2, New Rectangle(1, 1, Width - 3, Height - 3))
B.SetPixel(0, 0, C(1).Value)
B.SetPixel(Width - 1, 0, C(1).Value)
B.SetPixel(Width - 1, Height - 1, C(1).Value)
B.SetPixel(0, Height - 1, C(1).Value)
e.Graphics.DrawImage(B, 0, 0)
B3.Dispose()
G.Dispose()
B.Dispose()
End Sub
Private Down As Boolean
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Left Then
Down = True
Invalidate()
End If
MyBase.OnMouseDown(e)
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
Down = False
Invalidate()
MyBase.OnMouseUp(e)
End Sub
End Class
Class FProgressBar
Inherits Control
Private _Maximum As Double = 100
Public Property Maximum() As Double
Get
Return _Maximum
End Get
Set(ByVal v As Double)
_Maximum = v
Progress = _Current / v * 100
End Set
End Property
Private _Current As Double
Public Property Current() As Double
Get
Return _Current
End Get
Set(ByVal v As Double)
Progress = v / _Maximum * 100
End Set
End Property
Private _Progress As Double
Public Property Progress() As Double
Get
Return _Progress
End Get
Set(ByVal v As Double)
If v < 0 Then v = 0 Else If v > 100 Then v = 100
_Progress = v
_Current = v * 0.01 * _Maximum
Invalidate()
End Set
End Property
Sub New()
SetStyle(DirectCast(8198, ControlStyles), True)
Colors = New Pigment() { _
New Pigment("Border", 200, 200, 200), New Pigment("Backcolor1", 30, 30, 30), _
New Pigment("Backcolor2", 240, 240, 240), New Pigment("Highlight", 240, 240, 255, 255), _
New Pigment("Forecolor", 175, 175, 175), New Pigment("Gloss", 240, 240, 255, 255)}
End Sub
Const Count As Byte = 6
Private C As Pigment()
Public Property Colors() As Pigment()
Get
Return C
End Get
Set(ByVal v As Pigment())
If v.Length <> Count Then Throw New IndexOutOfRangeException
P1 = New Pen(v(0).Value)
P2 = New Pen(v(3).Value)
B1 = New SolidBrush(v(4).Value)
CB = New ColorBlend
CB.Colors = New Color() {v(5).Value, Color.Transparent, Color.Transparent}
CB.Positions = New Single() {0, 0.3, 1}
C = v
Invalidate()
End Set
End Property
Private P1, P2 As Pen
Private B1 As SolidBrush, B2 As LinearGradientBrush
Private CB As ColorBlend
Private G As Graphics, B As Bitmap
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
B = New Bitmap(Width, Height)
G = Graphics.FromImage(B)
G.Clear(C(2).Value)
G.FillRectangle(B1, New Rectangle(1, 1, CInt((Width * _Progress * 0.01) - 2), Height - 2))
B2 = New LinearGradientBrush(ClientRectangle, Color.Empty, Color.Empty, 90.0F)
B2.InterpolationColors = CB
G.FillRectangle(B2, ClientRectangle)
G.DrawRectangle(P1, New Rectangle(0, 0, Width - 1, Height - 1))
G.DrawRectangle(P2, New Rectangle(1, 1, Width - 3, Height - 3))
B.SetPixel(0, 0, C(1).Value)
B.SetPixel(Width - 1, 0, C(1).Value)
B.SetPixel(Width - 1, Height - 1, C(1).Value)
B.SetPixel(0, Height - 1, C(1).Value)
e.Graphics.DrawImage(B, 0, 0)
B2.Dispose()
G.Dispose()
B.Dispose()
End Sub
Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
Invalidate()
MyBase.OnSizeChanged(e)
End Sub
End Class
Main Form Source:
Code:
Option Strict On
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Public Class Form1
Dim StringForTextFile As String = ""
Private Sub WriteTextFile()
Dim f As String = SaveFileDialog1.FileName
Dim s As String = f.Substring(f.LastIndexOf("\"c) + 1)
StringForTextFile = RichTextBox1.Text
If File.Exists(filepath.Text) = True Then
Try
My.Computer.FileSystem.DeleteFile(filepath.Text) ' Delete file if it already exists first before you write new file
Catch ex As Exception
MessageBox.Show("Unable to replace the file. File may have been currupted or is attributed to prevent being modified. " & ex.ToString, " Save Failure ", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
End If
Try
Dim WriteTextFile As TextWriter
WriteTextFile = New StreamWriter(filepath.Text)
WriteTextFile.Write(StringForTextFile)
WriteTextFile.Close()
Catch ex As Exception
MessageBox.Show("Unable to write the file. " & ex.ToString, " File wasn't written ", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
RichTextBox1.Clear()
Dim intFirstChar As Integer = Me.RichTextBox1.GetCharIndexFromPosition(New Point(0, 0))
Dim intFirstLine As Integer = Me.RichTextBox1.GetLineFromCharIndex(intFirstChar)
Dim intCharCount As Integer = (Me.RichTextBox1.SelectionStart + Me.RichTextBox1.SelectionLength) - intFirstChar
Dim strFromStart As String = Me.RichTextBox1.Text.Substring(intFirstChar, intCharCount)
Dim intLine As Integer = strFromStart.Split(CChar(vbLf)).Length
ToolStripStatusLabel3.Text = " " & (intCharCount - strFromStart.LastIndexOf(vbLf))
ToolStripStatusLabel5.Text = " " & intFirstLine + intLine
SaveToolStripMenuItem.Enabled = False
AlwaysOnTopToolStripMenuItem.Checked = False
RichTextBox1.AllowDrop = True
'This is IMPORTANT for the Save Feature, it gets the directory to replace the existing file.
'filepath.Visible = False
'This will automatically make the textbox ready to type in when the form loads !important
RichTextBox1.Focus()
TitleFilename.Text = ""
ToolStripStatusLabel13.Text = " " & (Me.RichTextBox1.SelectionStart + Me.RichTextBox1.SelectionLength)
End Sub
Private Sub Form_Close(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If SaveToolStripMenuItem.Enabled = False Then
Application.Exit()
ElseIf SaveToolStripMenuItem.Enabled = True Then
Dim msg = "Do you want to save the current document first?"
Dim title = "Important"
Dim style = MsgBoxStyle.YesNoCancel
Dim response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
If filepath.Text = "filepath" Then
SaveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*"
SaveFileDialog1.InitialDirectory = "C:\"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> "" Then
FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
PrintLine(1, RichTextBox1.Text)
FileClose(1)
End If
Else
WriteTextFile()
End If
ElseIf response = MsgBoxResult.No Then
Application.Exit()
ElseIf response = MsgBoxResult.Cancel Then
e.Cancel = True
End If
End If
End Sub
Private PlaceHolder As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
Application.Exit()
End Sub
Private Sub ExitApp_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
If e.KeyCode = Keys.Escape Then
Application.Exit()
End If
End Sub
Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click 'DONE
If filepath.Text = "filepath" Then
If SaveToolStripMenuItem.Enabled = True Then
Dim msg = "Do you want to save the current document first?"
Dim title = "Important"
Dim style = MsgBoxStyle.YesNoCancel
Dim response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
SaveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> "" Then
FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
PrintLine(1, RichTextBox1.Text)
FileClose(1)
End If
RichTextBox1.Clear()
SaveToolStripMenuItem.Enabled = False
filepath.Text = "filepath"
TitleFilename.Text = ""
Exit Sub
ElseIf response = MsgBoxResult.No Then
RichTextBox1.Text = ""
filepath.Text = "filepath"
SaveToolStripMenuItem.Enabled = False
TitleFilename.Text = ""
Else
Exit Sub
End If
End If
ElseIf SaveToolStripMenuItem.Enabled = False Then
RichTextBox1.Clear()
filepath.Text = "filepath"
TitleFilename.Text = ""
End If
If Not filepath.Text = "filepath" Then
If SaveToolStripMenuItem.Enabled = True Then
Dim msg = "Do you want to save the current document first?"
Dim title = "Important"
Dim style = MsgBoxStyle.YesNoCancel
Dim response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
If File.Exists(filepath.Text) = True Then
TitleFilename.Text = ""
WriteTextFile()
RichTextBox1.Clear()
filepath.Text = "filepath"
SaveToolStripMenuItem.Enabled = False
End If
ElseIf response = MsgBoxResult.No Then
RichTextBox1.Clear()
filepath.Text = "filepath"
SaveToolStripMenuItem.Enabled = False
TitleFilename.Text = ""
Else
Exit Sub
End If
End If
End If
End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click 'DONE
If SaveToolStripMenuItem.Enabled = True Then
Dim msg = "Do you want to save the current document first?"
Dim title = "Important"
Dim style = MsgBoxStyle.YesNoCancel
Dim response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
If File.Exists(filepath.Text) = True Then
TitleFilename.Text = TitleFilename.Text
WriteTextFile()
ElseIf filepath.Text = "filepath" Then
SaveToolStripMenuItem.Enabled = False
SaveAsToolStripMenuItem.PerformClick()
End If
ElseIf response = MsgBoxResult.No Then
SaveToolStripMenuItem.Enabled = False
Else
Exit Sub
End If
End If
Dim AllText As String = "", Lineoftext As String = ""
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "All Files |*.*"
OpenFileDialog1.ShowDialog()
With OpenFileDialog1
If CBool(Windows.Forms.DialogResult.OK) Then
If OpenFileDialog1.FileName <> "" Then
Try
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
Do Until EOF(1)
Lineoftext = LineInput(1)
AllText = AllText & Lineoftext & vbCrLf
Loop
RichTextBox1.Text = AllText
Catch
Finally
FileClose(1)
Dim f As String = OpenFileDialog1.FileName
Dim s As String = f.Substring(f.LastIndexOf("\"c) + 1)
TitleFilename.Text = s
filepath.Text = OpenFileDialog1.FileName
SaveToolStripMenuItem.Enabled = False
End Try
End If
'Option Strict on disallows implicit conversions from 'system.windows.forms.dialogresult' to 'Boolean'
ElseIf CBool(Windows.Forms.DialogResult.Cancel) Then
TitleFilename.Text = TitleFilename.Text
End If
'Displays the Length value in status bar at bottom of application when file is opened
ToolStripStatusLabel13.Text = " " & (Me.RichTextBox1.TextLength)
End With
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click 'DONE
If filepath.Text = "filepath" Then
SaveAsToolStripMenuItem.PerformClick()
ElseIf File.Exists(filepath.Text) = True Then
TitleFilename.Text = TitleFilename.Text
WriteTextFile()
Else
SaveAsToolStripMenuItem.PerformClick()
End If
SaveToolStripMenuItem.Enabled = False
End Sub
Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click 'DONE
With SaveFileDialog1
SaveFileDialog1.InitialDirectory = "C:\"
SaveFileDialog1.FileName = ""
SaveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*"
SaveFileDialog1.ShowDialog()
If CBool(Windows.Forms.DialogResult.OK) Then
If SaveFileDialog1.FileName <> "" Then
FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
PrintLine(1, RichTextBox1.Text)
FileClose(1)
Dim f As String = SaveFileDialog1.FileName
Dim s As String = f.Substring(f.LastIndexOf("\"c) + 1)
TitleFilename.Text = s
filepath.Text = SaveFileDialog1.FileName
SaveToolStripMenuItem.Enabled = False
End If
ElseIf CBool(Windows.Forms.DialogResult.Cancel) Then
TitleFilename.Text = TitleFilename.Text
End If
End With
End Sub
'Drag enter
Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
'Shows the copy icon with dragging file over richtextbox
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
'NEED TO GET THE DROP TO ACTIVATE THE TEXT LENGTH OF THE EDITOR'S CONTROL
Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop 'DONE
Dim MyFiles() As String
ToolStripStatusLabel13.Text = " " & (RichTextBox1.TextLength)
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
If SaveToolStripMenuItem.Enabled = True Then
Dim msg = "Do you want to save the current document first?"
Dim title = "Important"
Dim style = MsgBoxStyle.YesNoCancel
Dim response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
MyFiles = CType(e.Data.GetData(DataFormats.FileDrop), String())
If filepath.Text = "filepath" Then
SaveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> "" Then
FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
PrintLine(1, RichTextBox1.Text)
FileClose(1)
End If
ElseIf File.Exists(filepath.Text) Then
WriteTextFile()
End If
SaveToolStripMenuItem.Enabled = False
filepath.Text = MyFiles(0)
' Display the file Name in titlebar
Dim f As String = MyFiles(0)
Dim s As String = f.Substring(f.LastIndexOf("\"c) + 1)
TitleFilename.Text = s
' Display the file contents
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(MyFiles(0))
ElseIf response = MsgBoxResult.No Then
MyFiles = CType(e.Data.GetData(DataFormats.FileDrop), String())
filepath.Text = MyFiles(0)
SaveToolStripMenuItem.Enabled = False
Dim f As String = MyFiles(0)
Dim s As String = f.Substring(f.LastIndexOf("\"c) + 1)
TitleFilename.Text = s
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(MyFiles(0))
Else
Exit Sub
End If
End If
If SaveToolStripMenuItem.Enabled = False Then
MyFiles = CType(e.Data.GetData(DataFormats.FileDrop), String())
RichTextBox1.Text = My.Computer.FileSystem.ReadAllText(MyFiles(0))
SaveToolStripMenuItem.Enabled = False
filepath.Text = MyFiles(0)
Dim f As String = MyFiles(0)
Dim s As String = f.Substring(f.LastIndexOf("\"c) + 1)
TitleFilename.Text = s
End If
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem.Click
RichTextBox1.Undo()
End Sub
Private Sub RedoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedoToolStripMenuItem.Click
RichTextBox1.Redo()
End Sub
Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click
RichTextBox1.Cut()
End Sub
Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
RichTextBox1.Copy()
End Sub
Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click
'This will paste the text unformatted so that it will always be copied into your Richtextbox with your default formatting settings.
RichTextBox1.Paste(DataFormats.GetFormat(DataFormats.Text))
End Sub
Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click
RichTextBox1.SelectAll()
End Sub
Private Sub ClearAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearAllToolStripMenuItem.Click
RichTextBox1.Text = ""
End Sub
Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
Dim fd As New Windows.Forms.FontDialog
fd.Font = RichTextBox1.Font
If fd.ShowDialog <> DialogResult.Cancel Then
RichTextBox1.Font = fd.Font
End If
End Sub
Private Sub FontToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextColorToolStripMenuItem.Click
Dim ffc As New Windows.Forms.ColorDialog
ffc.Color = RichTextBox1.ForeColor
ffc.Color = TitleFilename.ForeColor
ffc.Color = Label1.ForeColor
If ffc.ShowDialog <> DialogResult.Cancel Then
RichTextBox1.ForeColor = ffc.Color
TitleFilename.ForeColor = ffc.Color
Label1.ForeColor = ffc.Color
End If
End Sub
Private Sub BackgroundToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackgroundColorToolStripMenuItem.Click
Dim ffc As New Windows.Forms.ColorDialog
ffc.Color = RichTextBox1.BackColor
If ffc.ShowDialog <> DialogResult.Cancel Then
RichTextBox1.BackColor = ffc.Color
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MinimizeButton.Click
Me.WindowState = FormWindowState.Minimized
End Sub
'Updates line and column numbers as you type into the control or paste, (textchanged)
Private Sub RichTextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
Dim intFirstChar As Integer = Me.RichTextBox1.GetCharIndexFromPosition(New Point(0, 0))
Dim intFirstLine As Integer = Me.RichTextBox1.GetLineFromCharIndex(intFirstChar)
Dim intCharCount As Integer = (Me.RichTextBox1.SelectionStart + Me.RichTextBox1.SelectionLength) - intFirstChar
Dim strFromStart As String = Me.RichTextBox1.Text.Substring(intFirstChar, intCharCount)
Dim intLine As Integer = strFromStart.Split(CChar(vbLf)).Length
Me.ToolStripStatusLabel3.Text = " " & intFirstLine + intLine
Me.ToolStripStatusLabel5.Text = " " & (intCharCount - strFromStart.LastIndexOf(vbLf))
ToolStripStatusLabel13.Text = " " & (Me.RichTextBox1.TextLength)
If RichTextBox1.Modified Then
SaveToolStripMenuItem.Enabled = True
End If
End Sub
Private Sub RichTextBox1_TabKey(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
'key(value = TAB())
If e.KeyCode = Keys.Tab Then
If FormTabs.NumericUpDown1.Text = "2" Then
e.SuppressKeyPress = True
Me.RichTextBox1.SelectedText = " "
ElseIf FormTabs.NumericUpDown1.Text = "3" Then
e.SuppressKeyPress = True
Me.RichTextBox1.SelectedText = " "
ElseIf FormTabs.NumericUpDown1.Text = "4" Then
e.SuppressKeyPress = True
Me.RichTextBox1.SelectedText = " "
ElseIf FormTabs.NumericUpDown1.Text = "5" Then
e.SuppressKeyPress = True
Me.RichTextBox1.SelectedText = " "
ElseIf FormTabs.NumericUpDown1.Text = "6" Then
e.SuppressKeyPress = True
Me.RichTextBox1.SelectedText = " "
ElseIf FormTabs.NumericUpDown1.Text = "7" Then
e.SuppressKeyPress = True
Me.RichTextBox1.SelectedText = " "
ElseIf FormTabs.NumericUpDown1.Text = "8" Then
e.SuppressKeyPress = True
Me.RichTextBox1.SelectedText = " "
ElseIf FormTabs.NumericUpDown1.Text = "9" Then
e.SuppressKeyPress = True
Me.RichTextBox1.SelectedText = " "
Else
e.SuppressKeyPress = True
Me.RichTextBox1.SelectedText = " "
End If
End If
End Sub
'When user holds down Ctrl Key and uses the mouse scroll it will zoom in or out by 1.0F
Private Sub RichTextBox1_MouseWheel(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.MouseWheel
RichTextBox1.ZoomFactor = 1
End Sub
Private Sub DefaultSettingToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefaultSettingToolStripMenuItem.Click
'we have to give the default setting a reference zoom level, so we'll use the zoom as this
RichTextBox1.ZoomFactor = 1.5
'then from that we'll go back to 1 which should be the original zoom setting
RichTextBox1.ZoomFactor = 1
End Sub
'gets the line and column numbers in the status label when the cursor location is changed upon mouse click
Private Sub RichTextBox1_ClickCursor(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.MouseClick
Dim intFirstChar As Integer = Me.RichTextBox1.GetCharIndexFromPosition(New Point(0, 0))
Dim intFirstLine As Integer = Me.RichTextBox1.GetLineFromCharIndex(intFirstChar)
Dim intCharCount As Integer = (Me.RichTextBox1.SelectionStart + Me.RichTextBox1.SelectionLength) - intFirstChar
Dim strFromStart As String = Me.RichTextBox1.Text.Substring(intFirstChar, intCharCount)
Dim intLine As Integer = strFromStart.Split(CChar(vbLf)).Length
Me.ToolStripStatusLabel3.Text = " " & intFirstLine + intLine
Me.ToolStripStatusLabel5.Text = " " & (intCharCount - strFromStart.LastIndexOf(vbLf))
End Sub
'gets the line and column numbers in the status label when the cursor location is changed
Private Sub RichTextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyUp
Dim intFirstChar As Integer = Me.RichTextBox1.GetCharIndexFromPosition(New Point(0, 0))
Dim intFirstLine As Integer = Me.RichTextBox1.GetLineFromCharIndex(intFirstChar)
Dim intCharCount As Integer = (Me.RichTextBox1.SelectionStart + Me.RichTextBox1.SelectionLength) - intFirstChar
Dim strFromStart As String = Me.RichTextBox1.Text.Substring(intFirstChar, intCharCount)
Dim intLine As Integer = strFromStart.Split(CChar(vbLf)).Length
If e.KeyCode = Keys.Left Then
'This is associated with the line display so up and down arrow keys
Me.ToolStripStatusLabel3.Text = " " & intFirstLine + intLine
Me.ToolStripStatusLabel5.Text = " " & (intCharCount - strFromStart.LastIndexOf(vbLf))
End If
If e.KeyCode = Keys.Right Then
'This is associated with the line display so up and down arrow keys
Me.ToolStripStatusLabel3.Text = " " & intFirstLine + intLine
Me.ToolStripStatusLabel5.Text = " " & (intCharCount - strFromStart.LastIndexOf(vbLf))
End If
If e.KeyCode = Keys.Up Then
'This is associated with the column display so left and right arrow keys
Me.ToolStripStatusLabel5.Text = " " & (intCharCount - strFromStart.LastIndexOf(vbLf))
Me.ToolStripStatusLabel3.Text = " " & intFirstLine + intLine
End If
If e.KeyCode = Keys.Down Then
'This is associated with the column display so left and right arrow keys
Me.ToolStripStatusLabel5.Text = " " & (intCharCount - strFromStart.LastIndexOf(vbLf))
Me.ToolStripStatusLabel3.Text = " " & intFirstLine + intLine
End If
End Sub
Private Sub RichTextBox1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.SelectionChanged
'Get the text length of the selected text in the editor
ToolStripStatusLabel13.Text = CStr(RichTextBox1.SelectedText.Length)
'Get the total text length if there is no selection of text
If RichTextBox1.SelectedText.Length = 0 Then
ToolStripStatusLabel13.Text = CStr(RichTextBox1.TextLength)
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutButton.Click
MsgBox("This program was coded by Infinity ©2011" & vbNewLine & vbNewLine & " http://supportforums.net", MsgBoxStyle.Information, "About")
End Sub
Private Sub InfinityHomepageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InfinityHomepageToolStripMenuItem.Click
System.Diagnostics.Process.Start("http://www.supportforums.net/member.php?action=profile&uid=4546")
End Sub
Private Sub VisitSupportForumsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VisitSupportForumsToolStripMenuItem.Click
System.Diagnostics.Process.Start("http://www.supportforums.net")
End Sub
Private Sub UndoToolStripMenuItem1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem1.Click
UndoToolStripMenuItem.PerformClick()
End Sub
Private Sub RedoToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedoToolStripMenuItem1.Click
RedoToolStripMenuItem.PerformClick()
End Sub
Private Sub CutToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem1.Click
CutToolStripMenuItem.PerformClick()
End Sub
Private Sub CopyToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem1.Click
CopyToolStripMenuItem.PerformClick()
End Sub
Private Sub PasteToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem1.Click
PasteToolStripMenuItem.PerformClick()
End Sub
Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
If Clipboard.ContainsText Then
PasteToolStripMenuItem1.Enabled = True
Else
PasteToolStripMenuItem1.Enabled = False
End If
End Sub
Private Sub WordWrapToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WordWrapToolStripMenuItem.Click
If WordWrapToolStripMenuItem.Checked Then
RichTextBox1.WordWrap = False
WordWrapToolStripMenuItem.Checked = False
ToolStripStatusLabel7.Text = "Off"
Else
RichTextBox1.WordWrap = True
WordWrapToolStripMenuItem.Checked = True
ToolStripStatusLabel7.Text = "On"
End If
End Sub
Private Sub FindToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindToolStripMenuItem.Click
FormFind.Show()
If Me.RichTextBox1.SelectionLength = 0 Then
FormFind.txtFind.Text = ""
FormFind.btnReplaceAll.Enabled = False
Else
FormFind.txtFind.Text = Me.RichTextBox1.SelectedText
FormFind.btnReplaceAll.Enabled = True
End If
End Sub
Private Sub ReplaceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("This feature will be available at some point in other versions of this program", MsgBoxStyle.Information, "Not Available")
End Sub
Private Sub ToLowercaseToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToLowercaseToolStripMenuItem1.Click
ToLowerToolStripMenuItem.PerformClick()
End Sub
Private Sub ToUppercaseToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToUppercaseToolStripMenuItem1.Click
ToUpperToolStripMenuItem.PerformClick()
End Sub
Private Sub ToUpperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToUpperToolStripMenuItem.Click
RichTextBox1.SelectedText = RichTextBox1.SelectedText.ToUpper
End Sub
Private Sub ToLowercaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToLowerToolStripMenuItem.Click
RichTextBox1.SelectedText = RichTextBox1.SelectedText.ToLower
End Sub
Private Sub ReverseTextToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReverseTextToolStripMenuItem.Click
RichTextBox1.SelectedText = StrReverse(RichTextBox1.SelectedText)
End Sub
Private Sub AppendCurrentDateTimeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurrentDateTimeToolStripMenuItem.Click
RichTextBox1.SelectedText = FormatDateTime(Now)
End Sub
Private Sub AlwaysOnTopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlwaysOnTopToolStripMenuItem.Click
If AlwaysOnTopToolStripMenuItem.Checked Then
Me.TopMost = False
AlwaysOnTopToolStripMenuItem.Checked = False
ElseIf AlwaysOnTopToolStripMenuItem.Checked = False Then
Me.TopMost = True
AlwaysOnTopToolStripMenuItem.Checked = True
End If
End Sub
Private Sub AddCurrentDatetimeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddCurrentDatetimeToolStripMenuItem.Click
CurrentDateTimeToolStripMenuItem.PerformClick()
End Sub
Private Sub ZoomDefaultToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
RichTextBox1.ZoomFactor = CSng(1)
End Sub
Private Sub ZoomInToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
RichTextBox1.ZoomFactor = CSng(1.5)
End Sub
Private Sub ZoomOutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
RichTextBox1.ZoomFactor = CSng(0.5)
End Sub
Private Sub FindToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindToolStripMenuItem1.Click
FindToolStripMenuItem.PerformClick()
End Sub
Private Sub ReverseTextToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReverseTextToolStripMenuItem3.Click
ReverseTextToolStripMenuItem.PerformClick()
End Sub
Private Sub AllowDragDropToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllowDragDropToolStripMenuItem.Click
If AllowDragDropToolStripMenuItem.Checked Then
AllowDragDropToolStripMenuItem.Checked = False
RichTextBox1.AllowDrop = False
ElseIf AllowDragDropToolStripMenuItem.Checked = False Then
AllowDragDropToolStripMenuItem.Checked = True
RichTextBox1.AllowDrop = True
End If
End Sub
'Zoom options for the richtextbox
Private Sub HelpToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem1.Click
MsgBox("You can zoom in or out by holding down the Ctrl key and using your mouse scroll. If you want to go back to the default zoom setting for the text, just use the Default Settings option above this help button.", MsgBoxStyle.Information, "Zoom Help")
End Sub
Private Sub DefaultSettingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ZoomDefaultToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ZoomDefaultToolStripMenuItem.Click
DefaultSettingToolStripMenuItem.PerformClick()
End Sub
Private Sub HelpToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem2.Click
HelpToolStripMenuItem1.PerformClick()
End Sub
'This next bit will go to the current location of the I-beam within the editor (Richtextbox control)
Private Sub GotoCursorPositionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GotoCursorPositionToolStripMenuItem.Click
GotoCursorPositionToolStripMenuItem1.PerformClick()
End Sub
Private Sub GotoCursorPositionToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GotoCursorPositionToolStripMenuItem1.Click
RichTextBox1.ScrollToCaret()
End Sub
'This next bit of code just fixes a bug that I had with the class theme that I was using, not a big deal. From here on though is just the fix.
Private Sub MenuStrip1_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuStrip1.MouseMove
Cursor.Current = Cursors.Arrow
End Sub
Private Sub FileToolStripMenuItem_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.MouseMove
Cursor.Current = Cursors.Arrow
End Sub
Private Sub EditToolStripMenuItem_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.MouseMove
Cursor.Current = Cursors.Arrow
End Sub
Private Sub ViewToolStripMenuItem_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewToolStripMenuItem.MouseMove
Cursor.Current = Cursors.Arrow
End Sub
Private Sub FormatToolStripMenuItem_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FormatToolStripMenuItem.MouseMove
Cursor.Current = Cursors.Arrow
End Sub
Private Sub HelpToolStripMenuItem_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.MouseMove
Cursor.Current = Cursors.Arrow
End Sub
Private Sub StatusStrip1_MouseMove(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StatusStrip1.MouseMove
Cursor.Current = Cursors.Arrow
End Sub
Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.MouseUp
Cursor.Current = Cursors.Arrow
End Sub
Private Sub EditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditToolStripMenuItem.MouseUp
Cursor.Current = Cursors.Arrow
End Sub
Private Sub ViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewToolStripMenuItem.MouseUp
Cursor.Current = Cursors.Arrow
End Sub
Private Sub FormatToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FormatToolStripMenuItem.MouseUp
Cursor.Current = Cursors.Arrow
End Sub
Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.MouseUp
Cursor.Current = Cursors.Arrow
End Sub
Private Sub TitleFilename_Over(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles TitleFilename.MouseMove
Cursor.Current = Cursors.Arrow
Static lx As Single, ly As Single
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.Left = CInt(Me.Left + e.X - lx)
Me.Top = CInt(Me.Top + e.Y - ly)
Else
lx = e.X
ly = e.Y
End If
End Sub
Private Sub Label1_Over(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles Label1.MouseMove
Cursor.Current = Cursors.Arrow
Static lx As Single, ly As Single
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.Left = CInt(Me.Left + e.X - lx)
Me.Top = CInt(Me.Top + e.Y - ly)
Else
lx = e.X
ly = e.Y
End If
End Sub
Private Sub TitleFilename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TitleFilename.MouseDown
Cursor.Current = Cursors.Arrow
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.MouseDown
Cursor.Current = Cursors.Arrow
End Sub
'End of cursor settings codes
Private Sub TabConfigurationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabConfigurationToolStripMenuItem.Click
FormTabs.ShowDialog()
End Sub
Private Sub RichTextBox1_MouseWheel(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseWheel
End Sub
End Class
Find Form Source:
Code:
Public Class FormFind
Private PlaceHolder As Integer
'Only allow numbers in goto line textbox
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtGotoLine.KeyPress
txtGotoLine.ForeColor = Color.Black
If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 AndAlso Not IsNumeric(e.KeyChar) Then
e.Handled = True
Exit Sub
End If
End Sub
Private Sub frmFind_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtFind.Focus()
txtGotoLine.ForeColor = Color.Gray
txtGotoLine.Text = "Enter a line number..."
PlaceHolder = Form1.RichTextBox1.SelectionStart
If Form1.RichTextBox1.SelectionLength = 0 Then
Me.txtFind.Text = ""
btnReplaceAll.Enabled = False
Else
Me.txtFind.Text = Form1.RichTextBox1.SelectedText
btnReplaceAll.Enabled = True
End If
End Sub
'On form deactivated go to form make form a bit more transparent
Private Sub frmFind_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Deactivate
Me.Opacity = 0.75
End Sub
'On form activated go to full opacity
Private Sub frmFind_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Activated
Me.Opacity = 100
End Sub
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindNext.Click
Dim x As Integer
Dim opt As RichTextBoxFinds = 0
If ckCaseSensitive.Checked Then opt = opt Or RichTextBoxFinds.MatchCase
If ckWholeWord.Checked Then opt = opt Or RichTextBoxFinds.WholeWord
x = Form1.RichTextBox1.Find(txtFind.Text, PlaceHolder, opt)
PlaceHolder = Form1.RichTextBox1.SelectionStart + 1
'MsgBox("The text you searched for was not found in the document", MsgBoxStyle.Information, "Error")
If x < 0 Then
If MessageBox.Show("There are no more occurances of the text " & txtFind.Text & vbCrLf & "or the text does not exist in the document. Would you like to start from the beginning of the document?", "Not found", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
PlaceHolder = 0
btnFindNext.PerformClick()
End If
End If
End Sub
Private Sub btnReplace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplace.Click
If Form1.RichTextBox1.SelectionLength = 0 Then
MsgBox("Please make a selection over the text you wish to replace within the editor itself, then try again.", MsgBoxStyle.Information, "Information")
Exit Sub
ElseIf Form1.RichTextBox1.SelectionLength > 0 Then
Form1.RichTextBox1.SelectedText = txtReplace.Text
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub btnFindNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindNext.Click
End Sub
Private Sub btnReplaceAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReplaceAll.Click
Dim x As Integer
Dim opt As RichTextBoxFinds = 0
If ckCaseSensitive.Checked Then opt = opt Or RichTextBoxFinds.MatchCase
If ckWholeWord.Checked Then opt = opt Or RichTextBoxFinds.WholeWord
PlaceHolder = 0
Do
x = Form1.RichTextBox1.Find(txtFind.Text, PlaceHolder, opt)
If x < 0 Then
Exit Do
Else
Form1.RichTextBox1.SelectedText = txtReplace.Text
End If
PlaceHolder = Form1.RichTextBox1.SelectionStart + 0
Loop
End Sub
Private Sub txtFind_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFind.TextChanged
If txtFind.Text = "" Then
btnReplaceAll.Enabled = False
Else
btnReplaceAll.Enabled = True
End If
End Sub
Private Sub GoToLineAndColumn(ByVal RTB As RichTextBox, ByVal Line As Integer, ByVal Column As Integer)
Dim offset As Integer = 0
Dim i As Integer
For i = 0 To Line - 1
offset += Form1.RichTextBox1.Lines(i).Length + 1
Next i
Form1.RichTextBox1.Focus()
Form1.RichTextBox1.Select(offset + Column, 0)
End Sub
Private Sub GotoLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GotoLine.Click
Dim intFirstChar As Integer = Form1.RichTextBox1.GetCharIndexFromPosition(New Point(0, 0))
Dim intFirstLine As Integer = Form1.RichTextBox1.GetLineFromCharIndex(intFirstChar)
Dim intCharCount As Integer = (Form1.RichTextBox1.SelectionStart + Form1.RichTextBox1.SelectionLength) - intFirstChar
Dim strFromStart As String = Form1.RichTextBox1.Text.Substring(intFirstChar, intCharCount)
Dim intLine As Integer = strFromStart.Split(CChar(vbLf)).Length
'counts the total number of lines in the textbox
Dim totallines As Integer = Form1.RichTextBox1.Lines.Length.ToString()
'If the specified goto line, is greater than the total number of lines in the textbox
If txtGotoLine.Text > totallines Then
MsgBox("The line you specified is beyond the amount of lines you have within the editor currently. You will be directed to the end of the document", MsgBoxStyle.Information, "Line not found")
Me.GoToLineAndColumn(Form1.RichTextBox1, intLine, 0)
Exit Sub
Else
'0 is counted as the first line in integers so we'll minus 1 from the txtbox input to counter that.
Me.GoToLineAndColumn(Form1.RichTextBox1, (txtGotoLine.Text - 1), 0)
End If
End Sub
Private Sub txtGotoLine_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGotoLine.GotFocus
If txtGotoLine.Text = "Enter a line number..." Then
txtGotoLine.Text = ""
txtGotoLine.ForeColor = Color.Gray
ElseIf Not txtGotoLine.Text = "Enter a line number..." Then
txtGotoLine.ForeColor = Color.Black
End If
End Sub
Private Sub txtGotoLine_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGotoLine.LostFocus
If txtGotoLine.Text = "" Then
txtGotoLine.Text = "Enter a line number..."
txtGotoLine.ForeColor = Color.Gray
End If
End Sub
Private Sub RemoveDuplicate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveDuplicate.Click
Dim msg1 = "Are you sure you want to remove duplicate lines in the editor? (Note: This operation cannot be undone, and is Case Sensitive)"
Dim msg2 = "Are you sure you want to blank lines in the editor? (Note: This operation cannot be undone)"
Dim title = "Confirm Message"
Dim style = MsgBoxStyle.YesNoCancel
If CheckBox1.Checked Then
Dim response = MsgBox(msg1, style, title)
If response = MsgBoxResult.Yes Then
'Form1.RichTextBox1.Lines = Form1.RichTextBox1.Lines.Distinct.ToArray
Form1.RichTextBox1.Lines = Form1.RichTextBox1.Lines.Distinct.ToArray
ElseIf response = MsgBoxResult.No Then
Exit Sub
End If
ElseIf CheckBox2.Checked = False Then
Exit Sub
End If
If CheckBox1.Checked Then
Dim response = MsgBox(msg2, style, title)
If response = MsgBoxResult.Yes Then
Form1.RichTextBox1.Lines = Form1.RichTextBox1.Text.Split(New Char() {ControlChars.Lf}, _
StringSplitOptions.RemoveEmptyEntries)
ElseIf response = MsgBoxResult.No Then
Exit Sub
End If
ElseIf CheckBox1.Checked = False Then
Exit Sub
End If
End Sub
End Class
Form Tab Spacing Configuration Source:
Code:
Public Class FormTabs
Dim TabSpacingNumbers As String = "23456789" & vbBack
Private Sub FormTabs_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label3.Text = "Tab spacing is the number of spaces to use when the" & vbNewLine & "tab key is pressed."
End Sub
Private Sub SetValue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SetValue.Click
Me.Close()
End Sub
Private Sub DefaultTabSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefaultTabSettings.Click
NumericUpDown1.Text = "4"
Me.Close()
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumericUpDown1.KeyPress
If e.KeyChar = TabSpacingNumbers Then
e.Handled = True
End If
e.Handled = False
End Sub
End Class
Preview:
(See Part 2 for More - Click here)