Aligning the text in a Picturebox

i have a picture box in which i would be printing text. i would like to know how to align the text printed in the picturebox to the right and the center. by default it is always towards the left.
ayesha16Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

uncle_medCommented:
Have you tried the .Align property?
0
uncle_medCommented:
Actually Just took a close look at picturebox  control. You can use Align to move text. I am afraid you've got  to do it manually, using currentX and currentY methods. Here is a little  example:

Picture1.AutoRedraw = True
Picture1.CurrentX = 200
Picture1.CurrentY = 200
Picture1.Print "HELLO"
0
uncle_medCommented:
Sorry I meant to say "You can't use Align ...."
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

marconovaroCommented:

If you don't mind using API, there is this function:

Private Type RECT
     Left As Long
     Top As Long
     Right As Long
     Bottom As Long

End Type

Private Declare Function DrawText Lib "user32" Alias "DrawTextA" ( _
      ByVal hdc As Long, _
      ByVal lpStr As String, _
      ByVal nCount As Long, _
      lpRect As RECT, _
      ByVal wFormat As Long) As Long

That may help you.
Have a look here:

http://www.allapi.net/apilist/DrawText.shtml

HTH
M
0
PaulHewsCommented:
Private Sub Command1_Click()
    Dim strText As String
   
    strText = "Hello world"
   
    With Picture1
        'left aligned
        .CurrentX = 100
        Picture1.Print strText
       
        'Right aligned
        .CurrentX = .ScaleWidth - .TextWidth(strText) - 100
        Picture1.Print strText
       
        'Center aligned
        .CurrentX = .ScaleWidth / 2 - .TextWidth(strText) / 2
        Picture1.Print strText
   
   
   
   
   
   
    End With
End Sub
0
ayesha16Author Commented:
the allign property does not work. i have a picturebox and ithe text scrolls continously once i press the spacebar. the problem is the text which scrolls automatically in the picturebox keeps on flickering.the text in the picturebox is obtained from a textbox. So once i press the spacebar the text appears in the picturebox and scrolls from bottom to topof the picturebox.help me avoiding the flicker in the picturebox
0
marconovaroCommented:

The fastest way to avoid flickering is to set the "AutoRedraw" property of the picturebox to TRUE.
M
0
ayesha16Author Commented:
i have a richtext box and whatever i enter here is displayed in the picturebox. the problem is there is word wrap for the richtextbox and if the lenghth exceeds it automatically wraps to the second line. But since there is no enter key is pressed here the text printed in the picturebox does not word wrap and the entire contents of the text are printed in a single line. So it is not possible to view all the text content. Please help me solve this problem
0
marconovaroCommented:

As I said, you have to use DrawText with the DT_WORDBREAK flag. This will break lines in the rectangle bound you indicate.

Have a look here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_0odw.asp

M
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ayesha16Author Commented:
this does not help me. i want the text printed in a picturebox to have a word wrap.that means i have a multiline richtextbox. all the contents in this text box should get printed in the same order as the richtextbox even though there is a word wrap.
ie

this is a text
box

should get printed in the same order in the picturebox even if there is word wrap in the first line.
0
ayesha16Author Commented:
if the above is not possible tell me some way by which if i click a command button an enter key should be added to the end of every line in a multiline textbox.
0
ayesha16Author Commented:
i would like to know how to fit the contents of a richtextbox exactly in a picturebox even though the textbox contents are wrappable.the problem i encounter is whenever the text i type automatically comes to the next line without pressing the enter key then the content is printed in a single line in a picturebox.Only a part of the line is visible. i want the contents of picturebox also to word wrap and split itself according to how it is printed in the richtextbox. Please help me out. it is very urgent.
0
CleanupPingCommented:
ayesha16:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
PaulHewsCommented:
Points to marconovaro
0
CleanupPingCommented:
ayesha16:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
marconovaroCommented:
I guess that my solution should work... as suggested.
;-)
0
DanRollinsCommented:
Moderator, my recommended disposition is:

    Accept marconovaro's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.