Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Aligning the text in a Picturebox

Posted on 2003-03-10
17
Medium Priority
?
494 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

580 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