Monthly Archives: April 2015

Render outlined text in a WPF program using C#

The example Render text in a WPF program using C# shows how to draw basic text. This example uses the following overridden OnRender to draw outlined text. protected override void OnRender(DrawingContext drawingContext) { // Clear the background. Rect bg_rect = … Continue reading

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

Render text easily in a WPF program using C#

The example Render text in a WPF program using C# explains how to draw text in WPF code. This example uses the following extension method to make drawing text easier. // Draw text at the indicated location. public static void … Continue reading

Posted in drawing, extension methods, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , | 2 Comments

Render text in a WPF program using C#

Normally to display text in WPF you use some sort of object such as a Label or TextBlock, but you can draw text yourself if necessary. To make this easier, at design time I set the window’s Background property to … Continue reading

Posted in drawing, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , | 3 Comments

Render polygons and polylines in a WPF program using C#

WPF lets you do all sorts of interesting things that are much harder in Windows Forms applications. However sometimes, as in this example, it makes simple things much harder. (WPF’s slogan should be, “Twice as flexible and only five times … Continue reading

Posted in drawing, extension methods, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , , , , , | 2 Comments

Render dashed lines in a WPF program using C#

When you draw in WPF, you create a Pen object. You can set that object’s DashStyle to make the pen draw dashed or dotted lines. The following code shows how this example draws the second line from the top. Pen … Continue reading

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

Render an ellipse in a WPF program using C#

This example shows how you can render an ellipse in a WPF program. Normally to draw shapes in WPF you use some sort of object. You can add Ellipse, Line, Path, Polygon, Polyline, and Rectangle objects to a window and … Continue reading

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

Remove part of an image in C#

This example lets you remove part of an image. It lets you load an image file and then click and drag to select an area on the image. When you release the mouse, the program generates two new images: an … Continue reading

Posted in algorithms, geometry, graphics, mathematics | Tagged , , , , , , , , , , , , | Leave a comment

Size a font to fit a Label in C#

The following SizeLabelFont method shows how to size a font to fit a Label‘s text. It gives a Label the biggest font possible while still allowing its text to fit. // Copy this text into the Label using // the … Continue reading

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

FREE Book Drawing: Beginning Software Engineering

This drawing is over. I’m holding a drawing to give away 10 FREE copies of my latest book, Beginning Software Engineering. Relevant links: A brief description of the book The book’s Wrox web page All I ask in return is … Continue reading

Posted in books | Tagged , , , , | 6 Comments

Display an end user license agreement (EULA) in C#

Many program display an end-user license agreement (EULA) when they are installed or the first time they are run. This example uses a form called EulaForm to display a RichText format EULA file. The form returns DialogResult.OK if the user … Continue reading

Posted in forms, programs, registry | Tagged , , , , , , , , , | 3 Comments