Tag Archives: example program

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

Produce a repeatable series of “random” numbers in C#

The Random class can generate a series of pseudo-random numbers. They’re called “pseudo-random” rather than “random” because the numbers are generated by a mathematical algorithm rather than by some completely unpredictable process such as observing a source of radioactive decay … Continue reading

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

Safely manage documents in C#

This is a pretty involved example that shows how to safely manage documents. The pieces are all simple but there are a lot of tightly integrated pieces. This example lets you create, edit, open, and save files in text and … Continue reading

Posted in files, forms, user interface | 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

Create a class outside of any namespace statement in C#

When you create a class in C#, Visual Studio automatically puts it inside a namespace statement. If your project’s name is howto_remove_namespace, then by default that namespace is howto_remove_namespace. But did you know that you can create classes outside of … Continue reading

Posted in classes, syntax | Tagged , , , , , , , | 2 Comments

Book Review: The Manga Guide to Linear Algebra

(Occasionally I post reviews of book that I think may interest programmers, in this case admittedly only those with a mathematical inclination.) The Manga Guide to Linear Algebra   $24.95, 264 pages, 2012 By Shin Takahashi No Starch Press ISBN … Continue reading

Posted in books, mathematics | Tagged , , , , , , , , | Leave a 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

Make Ctrl+A select all of the text in a TextBox in C#

Often it’s convenient for the user to be able to press Ctrl+A to select all of the text in the TextBox that has the focus. Strangely that’s not the default behavior for the TextBox. Perhaps the TextBox doesn’t handle Ctrl+A … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , | Leave a comment