Category Archives: graphics

Draw “marching ants” dashed lines in C#

The example Draw dashed lines that are visible on any background in C# shows how to draw lines that are visible above any backgrounds. If the background is very cluttered, however, it may still be somewhat hard to see the … Continue reading

Posted in animation, drawing, graphics | Tagged , , , , , , , , , , , , , | 4 Comments

Draw dashed lines that are visible on any background in C#

This example shows how to draw dashed lines that are visible on any background. Sometimes it’s hard to draw lines that are visible on top of a photo or other complicated background. For example, when the user is clicking and … Continue reading

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

Get font size in pixels in C#

One oddity of the Font class is that its Size property returns font size in the units that were used to create the font. The Font class’s Unit property tells you the units used to create the font, but if … Continue reading

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

Draw smooth text in a GraphicsPath in C#

You can set a Graphics object’s TextRenderingHint property to AntiAliasGridFit to draw smooth text. However, if you place text in a GraphicsPath object and draw the GraphicsPath, then the TextRenderingHint property doesn’t give you smooth text. Instead you need to … Continue reading

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

Get the screen’s resolution in C#

Normally a monitor displays 96 logical (or “notional”) dots per inch (dpi) but it’s not necessarily a good idea to assume that value. When this example starts, the following code displays the logical resolution of the screen in dpi. private … Continue reading

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

Generate random polygons in C#

I needed a method for generating random polygons for a graphics program and the following code shows the result. // Make random polygons inside the bounding rectangle. private static Random rand = new Random(); public static PointF[] MakeRandomPolygon( int num_vertices, … Continue reading

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

Print a ListView with large contents in C#

The example Print the contents of a ListView control in C# explains how to print the data in a ListView control when its View property is set to Details. One difficulty when printing this kind of data is that a … Continue reading

Posted in controls, drawing, graphics, printing | Tagged , , , , , , , , , , , , , , | Leave a comment

Print the contents of a ListView control in C#

The ListView control, like most controls, includes no support for printing. If you want to display a ListView control’s contents on a print out, you need to do all of the printing yourself. Unfortunately printing in C# is extremely flexible … Continue reading

Posted in controls, drawing, graphics, printing | Tagged , , , , , , , , , , , , | 24 Comments

Make rectangle extension methods in C#

This example shows how to add rectangle extension methods to the Rectangle and RectangleF structs. The Rectangle and RectangleF structs have several useful properties for determining their geometry such as Left, Right, Top, and Bottom, but they have no midpoint … Continue reading

Posted in drawing, extension methods, graphics | Tagged , , , , , , , , , , , , , , | Leave a comment

Make silly eyes that track the mouse without flicker in C#

The example Make silly eyes that track the mouse in C# shows how to make eyes track the mouse position, but if you look closely as that program runs you will see a noticeable flicker. The solution is quite simple: … Continue reading

Posted in games, geometry, graphics | Tagged , , , , , , , , , , , , | 1 Comment