Ask the Expert

Putting text into an image control

How do I put data (text) into an image control?
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)
new System.Drawing.Font("Courier", 12), 
(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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: