Click here to Skip to main content
15,892,059 members
Articles / Programming Languages / Visual Basic

Notepad.NET - Creating a clone of notepad in Visual Basic

Rate me:
Please Sign up or sign in to vote.
2.57/5 (21 votes)
3 May 2008CPOL3 min read 129.3K   14.5K   41  
Creating a clone of notepad in Visual Basic
Imports System.Windows.Forms

Public Class FindDialog
    Dim target_pos As Integer


    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        frmMain.doc.Text = fp.Text


        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        FindText(1)
    End Sub
    Private Sub FindText(ByVal start_pos As Integer)
        Dim pos As Integer
        Dim target As String
        target = fp.Text

        If CheckBox1.Checked = True Then
            pos = InStr(start_pos, target, ttf.Text)
            If pos > 0 Then
                target_pos = pos
                fp.SelectionStart = target_pos - 1
                fp.SelectionLength = Len(target) - (Len(target) - Len(ttf.Text))
            Else
                MsgBox("Text Not Found")
            End If
        Else
            pos = InStr(start_pos, target.ToLower, ttf.Text.ToLower)
            If pos > 0 Then
                target_pos = pos
                fp.SelectionStart = target_pos - 1
                fp.SelectionLength = Len(target) - (Len(target) - Len(ttf.Text))

            Else
                MsgBox("Text Not Found")
            End If
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        FindText(target_pos + 1)
    End Sub

  
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions