[RESOLVED] Centering Text in Picture Box, How?
I am trying to centering text on a picture inside of a picture box but I am not able to do so. Here is my code:
VB Code:
Private Sub Command1_Click()
Dim strMSG As String
Dim sngX As Single
Dim sngY As Single
With Picture1
.AutoRedraw = True
.AutoSize = True
.Picture = Clipboard.GetData(vbCFBitmap)
.ForeColor = vbWhite
.Move (ScaleWidth / 2) - (.Width / 2), (ScaleHeight / 2) - (.Height / 2)
End With
strMSG = "Sample Text"
sngX = Int((Picture1.Width / 2) - (Len(strMSG)/2))
sngY = Int(Picture1.Height * 0.9)
Picture1.CurrentX = sngX ' Position where you want to print text
Picture1.CurrentY = sngY ' Position where you want to print text
Picture1.Print strMSG
End Sub
Also how would I print the text on the bottom of the picture.
Re: Centering Text in Picture Box, How?
Change this line:
sngX = Int((Picture1.Width / 2) - (Len(strMSG)/2))
to this:
sngX = (Picture1.Width - Picture1.TextWidth(strMSG)) / 2
Re: Centering Text in Picture Box, How?
Thanks again Rhino! :thumb:
Re: Centering Text in Picture Box, How?