Tag Archives: Rectangle

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

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

Convert a Rectangle into a RectangleF and vice versa in C#

The RectangleF structure has an overloaded assignment operator = that lets you simply set a RectangleF equal to a Rectangle, so converting a Rectangle into a RectangleF is easy. That makes sense because converting from Rectangle to RectangleF is a … Continue reading

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

Use a rubber band box to let the user select an area in a picture in C#

The following shows the program’s startup code. private Bitmap m_OriginalImage = null; private int X0, Y0, X1, Y1; private bool SelectingArea = false; private Bitmap SelectedImage = null; private Graphics SelectedGraphics = null; // Save the original image. private void … Continue reading

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

Align text drawn by DrawString in C#

This example shows how to use StringFormat objects and Rectangles to align text drawn in in C#. This example’s Paint event handler draws nine strings inside a rectangle, aligning them vertically and horizontally in the nine possible combinations of top/left, … Continue reading

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