Some Useful Snippets

When writing code there are some small segments that are used many times. In some cases a word or something will need to be deleted or changed. It is usually less effort to delete something than it is to add or change something. These examples are all in C# but similar snippets are good for most programming languages. There are many other similar kinds of snippets. As more snippets are added to the library the more likely it is to find a needed short message or piece of code.

When I create buttons and menus I use this message to fill in until the code for the action is written. The title for the message is taken from a variable in the Gbls class. This way each message box can be coordinated with the main program.

MessageBox.Show("Feature Not Implemented", Gbls.ProgTitle,
     MessageBoxButtons.OK, MessageBoxIcon.Information);

This snippet is to inform the user that the action failed.

MessageBox.Show("Action Failed", Gbls.ProgTitle,

This snippet is to confirm that the user wants to delete something.

if (MessageBox.Show("Are you sure you want to delete?", Gbls.ProgTitle,
         MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)

This snippet is for displaying how many items were found.

if (FoundCount == 0)
     MessageBox.Show("No Snips Found", Gbls.ProgTitle,
         MessageBoxButtons.OK, MessageBoxIcon.Information);
     MessageBox.Show(FoundCount.ToString() + " Snips Found", Gbls.ProgTitle,
         MessageBoxButtons.OK, MessageBoxIcon.Information);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.