Monthly Archives: December 2014

Draw on a bitmap in C#

This example shows how you can draw on a bitmap and display the result on a form. The example Draw in a Paint event handler in C# shows how to draw in a form’s Paint event handler. This is simple, … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , | 1 Comment

Draw in a Paint event handler in C#

Using images and drawing in the Paint event handler are the two most common ways to display graphics. Drawing in the Paint event handler is easy, but there are a couple of things you should keep in mind when you … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , | 11 Comments

Let controls share event handlers in C#

Sometimes it would be useful to let controls share event handlers. Often a program has several controls that do almost the same thing. It would be nice if they could share the same event handler to increase code reuse, but … Continue reading

Posted in controls, methods | Tagged , , , , , , , , , , , , | Leave a comment

Use the params keyword in C#

If you use the params keyword before an array parameter used as the last parameter in a method, then the calling code can pass any number of values for that parameter. The following code defines a ShowValues method that can … Continue reading

Posted in methods | Tagged , , , , , , , , , , , | 4 Comments

Split and join strings in C#

This example shows how you can use string methods to split and join strings. The string class’s Split method splits a string into pieces separated by delimiters. Different overloaded versions let you pass in an array of delimiters to use, … Continue reading

Posted in parsing, strings, variables | Tagged , , , , , , , , , , , | Leave a comment

Get the system’s board serial numbers and CPU IDs in C#

This example shows how to get the system’s board serial numbers and CPU IDs. WMI (Windows Management Instrumentation) lets you use SQL-like statements to ask the computer about itself. The GetBoardSerialNumbers function shown in the following code returns a list … Continue reading

Posted in system, WMI | Tagged , , , , , , , , , , , , | 3 Comments

Make a blinking label in WPF and C#

In Windows Forms, it’s trivial to make a blinking label. As for most other tasks, WPF makes this much harder but gives you some extra flexibility. In Windows Forms, you could add a Timer to a form and make it’s … Continue reading

Posted in animation, controls, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , | 1 Comment

Let the user move and resize a rectangle in WPF and C#

This example shows how you can let the user move and resize a Rectangle object at run time in a WPF program. The program’s XAML code defines a Canvas object that contains the Rectangle. The program catches the Canvas object’s … Continue reading

Posted in controls, graphics, wpf, XAML | Tagged , , , , , , , , , , , | 24 Comments

Register a program for a particular system in C#

This example demonstrates a fairly simple technique that you can use to register a program for a particular system. A determined hacker could circumvent it, but for most programs it won’t be worth the effort. The idea is simple. When … Continue reading

Posted in cryptography, programs, system, tools | Tagged , , , , , , , , , , , , | 2 Comments

Set form client size in C#

This example shows how to use the ClientSize property to set form client size. Many programmers know that a form’s ClientSize property gives the size of the area inside the form’s borders, but few know that you can set ClientSize. … Continue reading

Posted in controls, forms | Tagged , , , , , , , , , | Leave a comment