Monthly Archives: August 2015

List characters that are invalid in file and path names in C#

This example uses the following code to display characters that are invalid in file and path names. private void Form1_Load(object sender, EventArgs e) { string txt = “”; foreach (char ch in Path.GetInvalidFileNameChars()) { if (Char.IsWhiteSpace(ch) || Char.IsControl(ch)) txt += … Continue reading

Posted in files, strings | Tagged , , , , , , , , , , , | Leave a comment

Let the user pick database search criteria in C#

The top part of this program holds three columns of controls. The left column contains combo boxes holding the names of the fields in a database table. The middle column holds operators such as =, <, and >=. The right … Continue reading

Posted in database, user interface | Tagged , , , , , , , , , , , | 1 Comment

Flush click events in C#

If a button starts a long task, you probably don’t want the user to be able to click the button again (or perhaps not anything in the application) until the task finishes. The following code shows a straightforward attempt to … Continue reading

Posted in API, controls, events, syntax, system, threading | Tagged , , , , , , , , , , , , , | 12 Comments

Animate the Tower of Hanoi problem in C#

This example is similar to the example Recursively solve the Tower of Hanoi problem in C# except it uses animation to show how the disks move from one peg to another. The following AnimateMovement method moves a disk in a … Continue reading

Posted in algorithms, animation, drawing, graphics, multimedia, recursion | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Recursively solve the Tower of Hanoi problem in C#

The example Recursively draw a binary tree in C# uses recursion to draw the branches of a tree. Good examples of recursion are hard to come by because the human brain normally thinks iteratively. For example, if you need to … Continue reading

Posted in algorithms, drawing, recursion | Tagged , , , , , , , , , , , , , , | Leave a comment

Animate gears with unequal sizes in C#

The example Animate gears in C# shows how to animate three interlocked gears. Juan Manuel Montes asked, “What if the radius of the green gear is greater?” When two gears or wheels touch each other, their outer edges must rotate … Continue reading

Posted in algorithms, animation, graphics | Tagged , , , , , , , , , , | Leave a comment

Animate gears in C#

The example Draw gears in C# explains how you can draw gears in C#. That example only needs a couple small changes to animate the gears. The previous example starts drawing with angle theta = 0 so the first part … Continue reading

Posted in algorithms, animation, graphics | Tagged , , , , , , , , , , | 2 Comments

Draw an animated atom in C#

When the form’s Timer fires, its Tick event handler refreshes the form to force a redraw. The form’s Paint event handler draws the atom. private double Theta = 0; private const double Dtheta = Math.PI / 5; // Draw the … Continue reading

Posted in animation, drawing, graphics, multimedia | Tagged , , , , , , , , , , , | Leave a comment

Perform Windows Forms property animation in C#

Making a control’s properties change over time is called property animation. Keeping track of where a control’s properties, for example its position as it moves, can be tricky, particularly if you need to animate multiple objects at the same time. … Continue reading

Posted in algorithms, classes, multimedia | Tagged , , , , , , , , , , , , | 4 Comments

Compare the performance of if-else and switch statements in C#

The example Compare the speeds of the conditional operator (ternary operator ?:) and the if-else statement in C# compares the performance of two kinds of conditional tests. Johnny Boy pointed out that this didn’t include another kind of conditional statement: … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , , , , , | Leave a comment