Problem solve Get help with specific problems with your technologies, process and projects.

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.

Dig Deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.