|
-
May 15th, 2003, 04:27 AM
#1
Thread Starter
Member
Alignment in picturebox
Hi,
i have a picturebox. i would like to know how to align a large multiline text in the center of the picturebox when i press a command button. Could anyone please help me out this.
-
May 15th, 2003, 04:35 AM
#2
Frenzied Member
As a start, play around with TextWidth and TextHeight
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
May 15th, 2003, 05:24 AM
#3
Thread Starter
Member
Hi,
But how do i do it. Could u send me the source code for doing this
-
May 15th, 2003, 05:28 AM
#4
Frenzied Member
Here is an uncommented version. Step through (F8) the code, you should be able to see the logic.
The string is split by spaces, to retrieve each word. Then inside a loop each word is added to a temporary string (inserting the spaces as well). In each iteration this temporary string's width is compared with the picturebox's width to see whether it will fit in properly. When it exceeds the width, the loop is exited and the string is printed onto the box, the temporary string's contents are flushed and the loop is started again until all the words in the array are used up.
VB Code:
Private Const strData As String = "This is a sample text that should perhaps run " & _
"into more than three lines depending on the font " & _
"that is used to display the text in this picturebox." & _
"The technique I would suggest is to read this text into a " & _
"variable and split by a space and then print onto this " & _
"picture box depending on the position of the current " & _
"pixel in relation to the current font's TextHeight and/or TextWidth"
Private Sub Command1_Click()
Dim strDataArray() As String
Dim strToPrint As String
strDataArray = Split(strData, " ", -1, vbBinaryCompare)
i = 0
Do
If i > UBound(strDataArray) Then
Exit Do
End If
Do
If i > UBound(strDataArray) Then
Exit Do
End If
If (picBox.CurrentX + picBox.TextWidth(strToPrint & strDataArray(i))) > (picBox.ScaleWidth) Then
'i = i + 1
Exit Do
End If
strToPrint = strToPrint & strDataArray(i) & " "
picBox.CurrentX = (picBox.ScaleWidth - (picBox.TextWidth(strToPrint))) / 2
i = i + 1
Loop
picBox.Print strToPrint
strToPrint = ""
picBox.CurrentX = 0
Loop
End Sub
Private Sub Form_Load()
With picBox
.ScaleMode = vbPixels
.Font.Name = "Century Gothic"
.Font.size = 10
.Font.Bold = True
.Font.Italic = True
.Height = 300
.Width = 300
.AutoRedraw = True
End With
End Sub
HTH
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
May 16th, 2003, 12:07 AM
#5
Thread Starter
Member
Hi,
Thank You Very much for the reply. It worked.
-
May 16th, 2003, 12:27 AM
#6
Frenzied Member
Ur welcome
Cheers and Good Luck
Regards
KayJay
-
May 16th, 2003, 12:37 AM
#7
Thread Starter
Member
Hi,
Thank You Very much for the reply. It worked.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|