The Complete Source Code for a Notepad C# Application

Notepad Clone in C# .NET

I use notepad all the time, sometimes I just wanted to add one little feature, but it’s not extendable so I can’t. If I could just get my hands on the source code and if that source code was in C# I’d be set. So I decided to write a clone so I can do just that, and share it so that others could as well.

I attempted to make an exact clone and I think I did pretty good with three exceptions. One I decided I wanted a different icon so I can tell it apart from the actual notepad. Two, the real notepad has header and footer information as part of the page setup. I didn’t know how to do that since the page setup dialog is a system dialog. And three I didn’t try to duplicate the windows notepad help file.

As you can see from the screenshot it includes the following features:

  • File
    • New
    • Open
    • Save
    • Save As
    • Page Setup
    • Header & Footer (you can use variables to include filename, date, and other information)
    • Print
    • Exit
  • Edit
    • – Undo
    • – Cut
    • – Copy
    • – Paste
    • – Delete
    • – Find
      • Find next
      • Direction up/down
      • Match case
    • – Find Next
    • – Replace
      • Find next
      • Replace
      • Replace all
      • Match case
    •  Go To (a specific line number)
    •  Select All
    •  Time/Date (inserts the date and time e.g 9:18 PM 2/11/2014)
    • insert (e.g 9:18 PM 2/11/2014)
  • Format
    • Word Wrap
    • Font
  • View
    • Status bar (displays the line number and column number)
  • Help
    • View Help (you will have to provide your own documentation)
    • About Notepad Clone

Download Notepad Clone .NET Binary (exe)

You can get the source code at GitHub:

https://github.com/luisperezphd/NotepadClone

If you would like to be notified of future posts subscribe to my mailing list using the widget on the bottom.

Comments

  1. says

    i am new to c sharp and i am working on studying it .
    i hav been trying to built a notepad step by step studying different things in the process. one thing i havent found is to code the close button.
    its been done in your notepad
    could you please help me by letting me kno how u programmed the close button

    • says

      Hello KTBFFH, to answer your question accurately I would need details. But I’m guessing what you want is to get prompted to save your work if you try to close the application. The even you want to handle is the form close or closing event. It gives you an opportunity to cancel the close if you want. Note you can actually download the code and see exactly how I do it.

  2. says

    Hello,

    I made a similar clone of Notepad, for the same reasons, but mine was made in VB.Net, opposed to C#. Mine is available from Visual Studio’s extension gallery. I think that you should go through the process to submit yours there as well. Your version has a lot more features than mine, as I couldn’t manage to figure out the goto function and the status bar. I am currently working on a version that will include compiled HTML Help files, file encryption, a much improved replace all function(I just learned that string.replace existed), the goto feature, and other quirks available in MS Notepad; such as the .LOG function, and the different forms of encoding for files.

  3. says

    I am impressed by your work but I question the use of the word “clone”, which is an exact copy. I am very interested in this subject because I also love Notepad but needed some additional functionality.

    http://www.codeproject.com/Tips/563711/Encrypting-Editor-Notepad-replacement

    http://www.frank-t-clark.com/Professional/Papers/CryptPad/CryptPad.html

    I am constantly puzzled and frustrated by differences between my program’s operation compared to Notepad, which I am having great difficulty overcoming. I have consulted many different attempts by different people to make a clone or replacement. Almost all are very poor attempts. When I discovered your efforts I was impressed by how nearly complete your solution is.

    • says

      Hey Frank, thanks for taking the time to write.

      I checked out CryptPad it’s very good and it works as advertised.

      I tried my best to mimic Windows Notepad as much as possible and I’m open to any suggestions on how I can better accomplish that.

    • says

      LOL! The only solution I have found is to test, scratch my head, and write some more code. It is very time consuming and sometimes the solution is not clear. Notepad does some surprisingly sophisticated things. For example, the Undo function in Notepad has functionality not implemented in the standard Texbox control. Very difficult to duplicate without writing some massive code. Your program does not properly read files with ANSI characters as Notepad does. You don’t support encoding coversions, which Notepad does. Lots of little details. (Heavy sigh)

    • says

      Hey Frank, I added support for encoding conversion. While the actual encoding seems to be happening correctly, it doesn’t seem to be displayed the same way as notepad.

      The .NET code for detecting encoding seem to be able to distinguish between ANSI and UTF-8.

      This is definitely going to be a challenge.

      In the meanwhile I updated the files attached to this article with those changes.

    • says

      “It will be an interesting challenge.”

      What an understatement! The challenges seem to never end. The more I test my program the more differences I find and the harder it gets to correct them. Currently I am trying to figure out how to get the Edit, Delete function to Undo without writing a massive amount of code to brute force a solution. I believe there must be some simple procedure Notepad uses to get the textbox class to do the work, but I haven’t found it yet.

  4. says

    Hey i am new to Coding and c# so can you please make a Visual studio project for me instead of the source codes, so that i can open the project and run it and then edit it, thanks so much

    • says

      Hey Ash, There is no “solution” file packed with the source code, but there is a .csproj file. You should be able to open that file in Visual Studio to compile and run the project. Let me know if that works for you. Thanks.

    • says

      ok thanks, Can you please help me with one more thing. So my question is that you know how you have the file name on your Notepad Cloned up top that’s opened, so i was wondering if u can help me with that on Visual Basic.

      Please Help
      Thanks Ash

  5. says

    I am a newbie in c# ( though familiar with some other languages) and i wanted to send the text entered in notepad clone to the serial port.
    a google search revealed the code but where do i put it?

    • says

      Hey suvrat, there is no single right place to put it this is not so much a programming question then an application design question. The real question is when you want it to happen? How do you want the user to trigger it? Do you want it to replace save? In that case put it in place of the save code. Do you want it as a separate action? In that case add a menu item to the “File” menu called “Send to serial port” and add a click event to it. But really it’s up do you and where you think it makes sense for the user. Hope that helps.

  6. Steve G says

    Luis, I have to say this is probably the best “clone” around and helped me solve a few things I was trying to do in a small text editor. Good job and great contribution.

  7. Ashley says

    Nice job with the editor! I found a small bug – the line and column display doesn’t update if you move the cursor with the mouse. If you press a key on the keyboard it correctly updates to the current location.

    • Luis Perez says

      Thanks Ashley, I went ahead and made that fix. I also now made it available on GitHub, I updated the post with the URL.

  8. says

    Luis, your notepad is pretty sharp (haha I know). I’m just wondering if you were aware of the extreme lag that arises with a large volume of text. I loaded a text file (33kb in size) containing the first chapter of The Great Gatsby. No problem deleting or adding text near the beginning of the file, but try altering the document near the end gives you nothing but lag.

    It’s easy to find alot of c#’ers out there having the same problem, but I’ve yet to find anybody who has come across a solution to this. Have you, and are you going to implement it?

    Thanks and cheers!

    • Luis Perez says

      Hey Ben, thanks for pointing that out. It was a long time ago since I worked on that project, but I remember experiencing what you are talking about. I believe I tested this with just a plain textbox control and it still happened. So it might be the native control. If that’s the case there’s not much I can do about it except use an alternate control. Something like ScintillaNET maybe. I’ve never tried it myself but it kept coming up during my research.

  9. Zsolt says

    Greatest flaw of the original MS Notepad is that it can only search for text in one direction. If my cursor is at the end of the file, it simply can’f find anything unless I click the “up” radio button. It would be a huge improvement if there would be an option to search in the entire text without always checking the direction settings, and clicking additional widgets.

    • Luis Perez says

      Hey Zsolt, as much as possible I tried to mimic Notepad exactly. That way you know exactly what to expect. It’s been a while since I did this so I don’t remember if I implemented that detail exactly, but if I noticed it I would have. The goal of this project is exactly what you mentioned. It is a way for everyone to be able to customize any aspect of Notepad, I encourage you fork the code add that functionality and ideally share here for others who might want the same thing.

      I expect it would be pretty straight forward. There must be a start index where it starts searching, if it finds nothing you can simple change the start index to 0 and search again. What some applications do is display a popup that prompts the user “Not found do you want to search again from the beginning”.

Leave a Reply

Your email address will not be published. Required fields are marked *