Aligning Text in VB

CCrunnernb

Golden Member
Sep 14, 2000
1,002
0
76
How do you go about aligning text in a picture box? I've tried numerous times but always fall short of getting it to the right or to the left.

Thanks,

-Nick
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
What did you try? VB6 or .NET? .NET has a "textalign" property, set it to middleright. This might not apply to a picture box but it should.
 

DT4K

Diamond Member
Jan 21, 2002
6,944
3
81
Originally posted by: WarDemon666
Originally posted by: DT4K
How would you put text in a picturebox control?


print to it lol

example?

I don't see any text property or print method.

I don't think I've ever used a picturebox control in my 4 years of developing VB.

EDIT: nevermind. Like I said, I've never really used a picturebox control. I was playing around with it to see if I could help out the OP. Print method didn't come up in intellisense and VB help description for the PictureBox control didn't include Print in the list of methods. Then I tried doing a picbox.Print "Hello" and it ran but nothing showed up. But then I realized it was because I put the code in the form load event.
LOL, it's amazing how many little things I don't know even after spending the last 4 years of my life writing VB6 code.

As for the OP's question, you can change the CurrentX and CurrentY properties of your picturebox and that will tell it where to print the text. It looks like after each Print statement, the CurrentX value gets reset to 0 and the CurrentY value is incremented enough so the next Print statement will be on the next line.

PictureBox1.CurrentX = 0
PictureBox1.Print "First"
PictureBox1.CurentX = 1000
PictureBox1.Print "Second"

EDIT2: That will work to specify what position to start the text at. But if what you want is to actually have the text right aligned, I see two options.
1. Make a windows API call. Google for "vb6 picturebox alignment" and you will find examples.
2. Use the TextWidth method to find out how wide your text will be, then subtract this value from the Width of your picturebox to see where you should set the CurrentX to make the text look right-aligned.

Something like this:
PicBox1.CurrentX = PicBox1.Width - PicBox1.TextWidth("your text") + 100 ' the 100 is to add a little buffer space