Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display text in picture box 1

Status
Not open for further replies.

IFRs

Petroleum
Nov 22, 2002
4,658
I use a plain form to draw a picture using Line and Circle. How can I put text in the same form without using a text box? The problem with a text box is that when you re-size the form when running the program, the text box stays in the same absolute location and either disappears or obscures some of the drawing depending on what proportions the window is re-sized to. Re-sizing is necessary.
 
Replies continue below

Recommended for you

To write text directly on the picturebox you use the currentx and currenty properties and the print method. For example:
picturebox.currentx=<x coordinate for text>
picturebox.currenty=<y coordinate for text>
picturebox.print &quot;add your string here&quot;

You may have a similar problem when using this approach as the text will stay in the same place in the picturebox when you resize the form (unless you code it to do otherwise). You could add code to the resize event to move the text (this will work whether you are using the text box or text directly on the picturebox).
 
cowski -
Thanks - it worked just fine.
You get a star.
Questions:
1)How do I change the text height?
2)How do I make the text right or center justified?
 
Glad that I could be of help.

To change the text height use picturebox.font.size = 14 'text size in points.

You can also change the font with picturebox.font.name = &quot;font name&quot;. You will want to be careful about changing the font though, because it is possible that not everyone will have the font you want to use. If the specified font is missing the system will substitute, but the substitute may not be desirable.

As for the justification options (I hope I'm wrong but...) I think you'll have to take care of those yourself in code. I do know that there are functions that will return the length of the text string (actual physical length, not number of characters) taking into account the font size and character spacing. I don't remember the names of these functions offhand but when you find them you can use them to determine where to place currentx and currenty to get the desired justification.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor