Author Archives: RodStephens

About RodStephens

Rod Stephens is a software consultant and author who has written more than 30 books and 250 magazine articles covering C#, Visual Basic, Visual Basic for Applications, Delphi, and Java.

Use XAML and code behind to draw and outline shapes with gradients in WPF and C#

My unofficial slogan for WPF is, “Twice and flexible and only five times as hard,” and that applies to working with gradients. Gradients are undoubted cool and very flexible, but they are verbose and a bit tricky to use. How … Continue reading

Posted in drawing, graphics, wpf | Tagged , , , , , , , , , , , | Leave a comment

Let the user draw a smooth curve with WPF and C#

This example combines techniques used by the following examples. Draw a smooth curve in WPF and C# Let the user draw a smooth curve in C# The program uses the following code to keep track off what it is doing … Continue reading

Posted in drawing, graphics, wpf | Tagged , , , , , , , , | 2 Comments

Draw a smooth closed curve in WPF and C#

The post Draw a smooth curve in WPF and C# explains how you can create a series of Bézier curves to smoothly connect a group of points. This example shows how to modify that one to create a smooth closed … Continue reading

Posted in drawing, graphics, wpf | Tagged , , , , , , , , , , , | Leave a comment

Draw a smooth curve in WPF and C#

In Windows Forms programming, you can draw a smooth curve by using the Graphics object’s DrawCurve method. For some reason, Microsoft did not provide the ability to draw a smooth curve in WPF. Fortunatrely, you can use a series of … Continue reading

Posted in drawing, graphics, wpf | Tagged , , , , , , , , , | 2 Comments

Let the user draw a smooth curve in C#

This example lets the user click points to draw a smooth curve. When the user clicks the left mouse button, the program adds a point to the curve. When the user clicks the right button, the program stops drawing the … Continue reading

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

Delete files from multiple folders quickly and easily in C#

The example Delete files quickly and easily in C# lets you make a list of files matching a pattern, check the files that you want deleted, and then delete them all quickly. Reader Uldis posted a comment asking how to … Continue reading

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

Use sines and cosines to draw circles and ellipses in C#

This example shows how you can use trigonometric functions to draw circles. It’s such a basic technique that I often forget that it’s not completely obvious to everyone. Given a radius R and an angle θ, the equations x = … Continue reading

Posted in drawing, graphics, mathematics | Tagged , , , , , , , , , , | Leave a comment

“WPF 3d” code is avialable on GitHub

I have posted the source code for my book WPF 3d, Three-Dimensional Graphics with WPF and C# on GitHub in this repository. Feel free to download the examples and experiment with them. If you make any particularly interesting new images, … Continue reading

Posted in 3D, 3D graphics, books, graphics, three-dimensional graphics | Tagged , , , , , , , , , , | Leave a comment

Calculate the great circle distance between two latitudes and longitudes in C#

At a small scale, the world is relatively flat. At larger scale, however, is it roughly spherical. (Sorry flat-earthers.) That means the shortest distance between two points on the globe is not a straight line. (Unless you have amazing teleportation … Continue reading

Posted in mathematics | Tagged , , , , , , , , , | Leave a comment

Load Excel records into a DataGridView in C#

This example shows how you can load Excel records into a DataGridView control. You can use similar techniques to load Excel data into other controls such as other kinds of grid controls or a TreeView control. This example uses the … Continue reading

Posted in controls, database, Excel, interoperability | Tagged , , , , , , , , , , , , | 2 Comments