Title: Draw text with colors reversed along a diagonal line in C#
The post Draw text with colors reversed in its upper and lower halves in C# showed how you can draw text that has upper and lower halves with colors switched. This example uses a similar technique to switch the colors along a diagonal line.
The approach is similar to the one used by the previous example. The program creates two bitmaps that hold the text drawn with the different color combinations. The following code snippet draws the upper right and lower left parts of the drawing area.
// Fill the entire rectangle with the top version.
using (TextureBrush brush = new TextureBrush(bm_top))
// Fill the lower left corner with the bottom version.
Point points =
new Point(rect.X, rect.Y),
new Point(rect.X, rect.Bottom),
new Point(rect.Right, rect.Bottom),
using (TextureBrush brush = new TextureBrush(bm_bottom))
Instead of filling two triangular pieces, this code first fills the entire drawing area with the colors that should be in the upper right corner. Filling the upper right corner specifically wouldn't be too hard, but this is slightly easier.
Next, the code creates an array of points to define the lower left triangular area and uses the Graphics object's FillPolygon method to fill that area with the lower-left colors.
That's all there is to it. In my next post, I'll show how to make one more variation that divides the text into pieces on either side of a sine curve.
Download the example to experiment with it and to see additional details.