Computer Science 213

C# Code Snippets for Visual Studio 2005

When you need code for a specific job, then check out this list. Instead of scrounging around in your notes, I put some major code snippets here for you. In most cases they are copied from our C# classroom projects.

 
  • Forms

 

Change form background color or change form size at run time.
Make ENTER key work like TAB

How to launch a browser & go to URL
  • Data Entry
  • Managing Data Entry Issues

Copy selected item in Listbox to a textbox
How to
concatenate strings
Simple math operations (
computing sales tax)
How to display items & pricing as currency

  • Event Handlers
  • Using List Boxes

Add Item to list box
Remove list box item
Load list box with items & pricing information at design time
Load List Box with Items & Pricing at run time
Getting the list box items, pricing, & photo information
Foreach Loop and listboxes
  • Menus & Windows Dialog Boxes
Using Drop-Down menus and Windows dialogs
Using OpenFile Dialog Box
  • Using Controls

Web Browser control
How to display image in a picture box
 
  • If , Switch, & Loops
  • Formatting Strings

How to format numbers
How to format data as currency
How to create multi-line text in a label
 
  •  Custom Methods
How to create custom methods (functions)
  • String Functions

How to use the TRIM function
Using Substring instead of Left, Mid, Right
 
  • Variables

How to use module-level variables
Using Totals & Counts with module-level variables
Using variables to add contents of textboxes
 
  • Collections

foreach Loop using a list box
foreach loop to find textboxes in the controls collection
foreach loop for clearing textbox controls inside a container control
 

 

  • File I/O
  • Classes

Introduction to Classes Part 1
Introduction to Classes Part 2

 

  • ADO Stuff

DataSources and SQL with error handling
Read SQL DB using ADO in Code 

 

  • Extras

C# Support

Database Resources

 


Return to Main Menu

Copyright © 1999-2008 Ronald P. Kessler, Ph.D.
All rights reserved.

Revised: April 06, 2010