473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

picturebox

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
Nov 21 '05 #1
5 1827
Nak
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.
Nov 21 '05 #2
"Frank" <fr***@frank.com> wrote in message
news:cf**********@news2.tilbu1.nb.home.nl...
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.
Nov 21 '05 #3
* "Nak" <a@a.com> scripsit:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
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


"Frank" <fr***@frank.com> wrote in message
news:cf**********@news2.tilbu1.nb.home.nl...
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

Nov 21 '05 #5
Nak
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.
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for...
3
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
4
by: munibe | last post by:
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named customer_button, my wish is to add a new small...
3
by: kirk | last post by:
I have a form with a PictureBox control on it. The .Image property is set to a PNG file(which shows the picture of the US map) with some transparency in it. The .BackColor property is set to...
5
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.