Click here to Skip to main content
15,127,310 members
Articles / .NET
Posted 17 Mar 2021

Tagged as


3 bookmarked

Copy-Cutter: Code 'Snippet' Manager for Windows

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
17 Mar 2021CPOL5 min read
A tool to help quickly generate 'snippets' of code in any Windows based IDE
Copy-Cutter lets you quickly create code-snippets you can immediately add to your work. 'Text' mode lets you parse out lists of variable names and let Copy-Cutter generate the code snippet for each variable in the list and paste it from the MS-Clipboard.

Image 1

Microsoft's Snippets are great, but sometimes they just don't do enough. Cut-n-paste comes in handy when you have a lot of similar bits of code to write that only differ in the names of the variables you're instantiating, sampling or setting. Even though Snippets can quickly build the frame-work for For-Loop's or nested If-Else statements, you can't use them to generate a sequence of similar lines-of-code for a list of variables or objects that are all virtually the same with little or no difference between them. Even though you can create your own MS Visual Studio snippets to add to the existing list, there is a bit of work involved in doing that, code snippets are relatively limited and you may not even be writing in a Visual Studio IDE anyway. VS Snippets will help you set up a For-Loop, an Enum or Do-While, but they won't help you instantiate a bunch of buttons that you need to set Colors and Fonts, add Text to. There's still a bit of typing involved in doing that.

Here's where the Copy-Cutter app comes in. It's really quite a simple app to use.

  • Click the 'Format Editor' button on the Copy-Cutter form.
  • Select a Format from the Format Editor's list (or create the format you want) and Click 'Ok'.
  • Copy/Cut as much code (e.g., Variable or Object names) into Microsoft's Clipboard.
  • Click the 'Clipboard - Dump' button on the Copy-Cutter.
  • Position the mouse cursor in your work-space where you want to insert the generated code.
  • Paste the generated code into your project.

Have a look at this video.

Let's say, for example, you needed to create a few buttons that all do basically the same thing.

Your method might look like this:

void Example()
            //                         Button - var1
            System.Windows.Forms.Button btnvar1 = new System.Windows.Forms.Button();
            btnvar1.Text = "var1";
            btnvar1.AutoSize = true;
            btnvar1.BackColor = System.Drawing.Color.Blue;
            btnvar1.ForeColor = System.Drawing.Color.Yellow;
            btnvar1.KeyDown += Btnvar1_KeyDown;
            btnvar1.KeyUp += Btnvar1_KeyUp;

            //                         Button - var2
            System.Windows.Forms.Button btnvar2 = new System.Windows.Forms.Button();
            btnvar2.Text = "var2";
            btnvar2.AutoSize = true;
            btnvar2.BackColor = System.Drawing.Color.Blue;
            btnvar2.ForeColor = System.Drawing.Color.Yellow;
            btnvar2.KeyDown += Btnvar2_KeyDown;
            btnvar2.KeyUp += Btnvar2_KeyUp;

            //                         Button - var3
            System.Windows.Forms.Button btnvar3 = new System.Windows.Forms.Button();
            btnvar3.Text = "var3";
            btnvar3.AutoSize = true;
            btnvar3.BackColor = System.Drawing.Color.Blue;
            btnvar3.ForeColor = System.Drawing.Color.Yellow;
            btnvar3.KeyDown += Btnvar3_KeyDown;
            btnvar3.KeyUp += Btnvar3_KeyUp;

            //                         Button - var4
            System.Windows.Forms.Button btnvar4 = new System.Windows.Forms.Button();
            btnvar4.Text = "var4";
            btnvar4.AutoSize = true;
            btnvar4.BackColor = System.Drawing.Color.Blue;
            btnvar4.ForeColor = System.Drawing.Color.Yellow;
            btnvar4.KeyDown += Btnvar4_KeyDown;
            btnvar4.KeyUp += Btnvar4_KeyUp;

These buttons you've created are virtually the same. You could write the first one, then cut-n-paste the rest and change the variable names for each one. But that's still a lot of work.

Using this app, you would go to the Format Editor. Create the format you need (if it's not already saved in your format list). Select it, click 'ok'. Then write the names of each variable one at a time into the MS Clipboard (type the name, highlight it and press Ctrl-X). Then dump-it-all to the Clipboard using the 'Clipboard-Dump' button and when you paste it into your work, it will look exactly as it appears above.

Here's what the Format Editor needs to look like when you've created the appropriate format for this particular example.

Image 2

The words <Source_Text> will be replaced by whatever you copied to the Clipboard. What happens is, every time you copy text to the clipboard while the CopyCutter app is on, that text will be added to a growing list of text (usually Variable or Object names). When you click the 'Clipboard - Dump' button each item in the list that you copied to the clipboard will generate the formatted text above with the Variable/Object name replacing the tag <Source_Text> found in your selected format.

Since you write the Formats into the Copy-Cutter yourself, they can be tailored to your exact needs and are not limited to Visual Studio or any other language. You can use this in Arduino, Python, Assembly or even your own Mark-Up creations. You need not type the <Source_Text> tag in the Format Editor but simply press the same Control-Insert key-combination that Shows/Hides the app while it's running in the background waiting for your call.

The code needed to do this itself is relatively simple. All the formats are saved to an XML file which you need never bother with. The Format Editor's interface is user friendly enough that you can create your own formats on the fly and use them whenever you like.

Now, in the example above, you've generated the buttons but they have events attached to them. You will have to generate the events as well and that can be a hassle. Most times, you'll just hit the Tab-key after the '+=' before the event name when you're defining the button but since we had Copy-Cutter generate that code for us we'll have to use the Copy-Cutter to generate the event handlers as well. No problem.

  • Summon Copy-Cutter to the screen (if you have it in the background just click Ctrl-Insert).
  • Click the 'Format Editor' button on the Copy-Cutter form.
  • Select the Event-Standard format from the list and press 'ok'.
  • Copy the Event names from your code to the Clipboard.
  • Press 'Clipboard - Dump'.
  • Paste the code to your app.

All this saves a lot of time.

Maybe you like the monotonous brain-dead tedium of writing all these by hand or maybe you don't, but either way, this app makes writing code much quicker.

The example above can be made even faster if you just type the names of the variables in one line of text with a single space between them, then define the 'Parse String Delimiter' as a single space (or any text that separates them all from each other) and copy the entire line to the MS Clipboard. Copy Cutter will look at the 'Parse String Delimiter' and break the copied text up into the separate variable names. So, in this way, you can create the entire method by just typing the names of the variables then Cut & Paste the lot into your project using this simple easy-to-use app.

Alternately, you could toggle the 'Live-Swap' option On. This feature allows you to cut/paste one Variable/Object name at a time and produce the same code. When this option is On, the app will NOT accumulate a list and wait for you to press Clipboard-Dump but rather generate the code you formatted each time you copy something to the MS clipboard and replace the content of the clipboard with the formatted code you want. Just Cut and immediately Paste wherever you like.

I use it all the time. Presto-magico, its freakin' awesome.

Convenient, versatile, user-friendly, all it needs now is a mini-bar but you'll have to put that on your tab along with room service.


  • 17th March, 2021: Initial version
  • 1st April, 2021 : fixed issue with Load Format 


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


About the Author

Christ Kennedy
CEO unemployable
Canada Canada
Christ Kennedy grew up in the suburbs of Montreal and is a bilingual Quebecois with a bachelor’s degree in computer engineering from McGill University. He is unemployable and currently living in Moncton, N.B. writing his next novel.

Comments and Discussions

GeneralMy vote of 5 Pin
Vincent Radio17-Mar-21 10:26
professionalVincent Radio17-Mar-21 10:26 
GeneralRe: My vote of 5 Pin
Christ Kennedy17-Mar-21 13:44
mvaChrist Kennedy17-Mar-21 13:44 
its friggin' handy.
my code is perfect until i don't find a bug...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.