picturebox

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

Hi,
is there a way to put text into a picturebox. For example when displaying
only the background color with some text on top? Or are there better
controls for that. I considered a label but is does not stretch images.
Thanks
Frank
 
Hi Frank,

Check out the Graphics and Drawing namespaces. You can do anything you
want with a picturebox!

PictureBox1.CreateGraphics.DrawString("Nuts", PictureBox1.Font, New
SolidBrush(PictureBox1.ForeColor), 0, 0)

This will write the word "Nuts" into a picturebox at location 0,0. Hope
this helps!

Nick.
 
Frank said:
Hi,
is there a way to put text into a picturebox. For example when displaying
only the background color with some text on top? Or are there better
controls for that. I considered a label but is does not stretch images.
Thanks
Frank

You could put a textbox in front it and either hide it or send it to the
back when not needed I believe.
 
* "Nak said:
Check out the Graphics and Drawing namespaces. You can do anything you
want with a picturebox!

PictureBox1.CreateGraphics.DrawString("Nuts", PictureBox1.Font, New
SolidBrush(PictureBox1.ForeColor), 0, 0)

Notice that it's better to dispose the 'SolidBrush' to clean up
unmanaged resources quickly, and to dispose the 'Graphics' object
created by 'CreateGraphics':

\\\
Dim g As Graphics = PictureBox1.CreateGraphics(...)
Dim sb As New SolidBrush(...)
g.DrawString(..., sb, ...)
sb.Dispose()
g.Dispose()
///
 
You can service the PictureBox Paint event and use DrawString to output the
text to the Graphics device provided in the event arguments. Use
StringFormat to align the text vertically and/or horizontally in the area.

See the GDI+ FAQ #1 most-asked question for why it's not a good idea to use
CreateGraphics.

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
Hi Bob,
See the GDI+ FAQ #1 most-asked question for why it's not a good idea to use
CreateGraphics.

LOL, 'Twas mearly a quick and dirty example!

Nick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top