As one of the examples in the Extending MFC Applications with the .NET book, I illustrated how to store and retrieve BLOB (binary large objects) to and from a SQL Server database. These BLOBs were actually image data that was rendered on the dialog when the user selected them. Since then, I've had numerous requests to illustrate more of the GDI+ capabilities from the Managed Extensions to C++ for .NET (MC++). Therefore, in this first in a series of GDI+ articles, I'll start by illustrating how to draw text (both hatch and gradient) using GDI+ brushes.

Here are some basic steps for drawing either hatched or gradient text using GDI+.
private: System::Void picText_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e)
{
...
Graphics* g = e->Graphics;
using namespace System::Drawing; ... Font* font = new Font(S"Times new Roman", 20, FontStyle::Regular);
SizeF textSize = g->MeasureString(S"My Sample Text", font);
// HatchBrush example
Brush* brush = new HatchBrush(HatchStyle::Cross,
Color::Black, Color::Blue);
// LinearGradientBrush example
RectangleF* rect = __nogc new RectangleF(PointF(0, 0), textSize);
brush = new LinearGradientBrush(*rect,
Color::Black,
Color::Blue,
LinearGradientMode::ForwardDiagonal);
The Graphics::FillRectange method enables you to specify a Brush object of your choosing as well as the exact rectangular coordiates to use. Regarding the Brush object, you can either instantiate a custom Brush or use the SystemBrushes object that defines property members that are each a SolidBrush representation of a Windows display element. These are the elements that are defined via the Windows Display Properties and include ActiveBorder, ActiveCaption and so on.
// Use the Windows-defined colour for controls
// and explicitly state the rectangle coordinates
g->FillRectangle(SystemBrushes::Control,
picText->Left,
picText->Top,
picText->Right - picText->Left,
picText->Bottom - picText->Top);
// Colour the entire drawing surface using White
g->Clear(Color::White);
// Center the text on the drawing surface
g->DrawString(txtToDisplay->Text,
font,
brush,
(picText->Width - textSize.Width) / 2,
(picText->Height - textSize.Height) / 2);