If you mean the System.Windows.Forms.PictureBox class for Windows Forms applications, it's as easy as overriding the Paint event for the control and invoking the DrawString method on the PaintEventArgs Graphics member. For example:
private void pictureBox1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawString("Foo",
new System.Drawing.Font("Courier", 12),
System.Drawing.Brushes.Black,
(float)0.0, (float)0.0);
}
If you mean the System.Web.UI.WebControls.Image class for Web Forms applications, the only thing you can really do is specify an alternate text string and not set a valid URL for the ImageUrl property. Of course, you can always create an image file on the fly using the .NET drawing routines and then render that dynamically generated image file by specifying it as the ImageUrl property of the Image control. Jeff Prosise's Wicked Code column in MSDN Magazine August 2002 issues shows how to do this.
This was first published in May 2004