?
Solved

Aligning the text in a Picturebox

Posted on 2003-03-10
17
Medium Priority
?
485 Views
Last Modified: 2010-04-07
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.
0
Comment
Question by:ayesha16
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +3
17 Comments
 
LVL 2

Expert Comment

by:uncle_med
ID: 8101833
Have you tried the .Align property?
0
 
LVL 2

Expert Comment

by:uncle_med
ID: 8101862
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
 
LVL 2

Expert Comment

by:uncle_med
ID: 8101863
Sorry I meant to say "You can't use Align ...."
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:marconovaro
ID: 8101973

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
 
LVL 38

Expert Comment

by:PaulHews
ID: 8102929
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
 

Author Comment

by:ayesha16
ID: 8117091
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
 
LVL 6

Expert Comment

by:marconovaro
ID: 8117567

The fastest way to avoid flickering is to set the "AutoRedraw" property of the picturebox to TRUE.
M
0
 

Author Comment

by:ayesha16
ID: 8124348
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
 
LVL 6

Accepted Solution

by:
marconovaro earned 80 total points
ID: 8125997

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
 

Author Comment

by:ayesha16
ID: 8126434
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
 

Author Comment

by:ayesha16
ID: 8126647
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
 

Author Comment

by:ayesha16
ID: 8149464
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
 

Expert Comment

by:CleanupPing
ID: 8900407
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
 
LVL 38

Expert Comment

by:PaulHews
ID: 8906884
Points to marconovaro
0
 

Expert Comment

by:CleanupPing
ID: 9056483
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
 
LVL 6

Expert Comment

by:marconovaro
ID: 9062249
I guess that my solution should work... as suggested.
;-)
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9074636
Moderator, my recommended disposition is:

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

DanRollins -- EE database cleanup volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question