Overlaying labels with text

I need to put some text on a form so that it goes across two adjacent label controls.  Te text is to be printed letter by letter going vertically down the centre of the labels.  Can anyone suggest a way to do this given the way VB layers print text and controls
Who is Participating?
This is why I said that you need to set the ZOrder property to put the text box in the Front. The labels, being in the back, will be rendered *first* and then overlain by the text box. This should give you the effect you're after.


I'm not sure I understand exactly what you mean.
Would setting the BackStyle of the labels to transparent help?

Can you explain a bit more what you are trying to do?
It looked to me you want to print some text vertically.
Here is the code to do that.

       1. In the form's General declaration area, add:
       Private Type LOGFONT
         lfHeight As Long
         lfWidth As Long
         lfEscapement As Long
         lfOrientation As Long
         lfWeight As Long
         lfItalic As Byte
         lfUnderline As Byte
         lfStrikeOut As Byte
         lfCharSet As Byte
         lfOutPrecision As Byte
         lfClipPrecision As Byte
         lfQuality As Byte
         lfPitchAndFamily As Byte
         lfFacename As String * 33
       End Type

       Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
       Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
       Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

       ' 2. Add the function
       Private Function fRotateText(ByVal theText As String, ByVal theSize As Integer, ByVal theAngle As Integer, ByVal theX As Long, ByVal
       theY As Long) As Boolean

       'Name:      fText90D
       'Author:    Dalin Nie
       'Date:      2/18/98
       'Purpose:   Print a 90 degree text in the form
       'Pass In:   TheText-- the text you want to print
       '           theSize:   Size of the font
       '           theAngle:  How many degree's you want to rotate
       '           theX, theY, Where you wnat your text
       'Return:    Boolean

         On Error GoTo Trap
         Dim F As LOGFONT, hPrevFont As Long, hFont As Long, FontName As String
         Dim FONTSIZE As Integer
         FONTSIZE = theSize

         F.lfEscapement = 10 * theAngle 'rotation angle, in tenths
         FontName = "Arial Black" + Chr$(0) 'null terminated
         F.lfFacename = FontName
         F.lfHeight = (theSize * -20) / Screen.TwipsPerPixelY
         hFont = CreateFontIndirect(F)
         hPrevFont = SelectObject(Me.hdc, hFont)
         CurrentX = theX
         CurrentY = theY
         Print theText
       '  Clean up, restore original font
         hFont = SelectObject(Me.hdc, hPrevFont)
         DeleteObject hFont
         fRotateText = True
         Exit Function


       End Function

       ' add a label, name it lable On, set backstyle to transparent
       ' add a command button,

       Private Sub Command1_Click()
       Call fRotateText("My Text", 12, 90, Label1.Left, Label1.Top + Label1.Height)
       End Sub

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.

TaranadillaAuthor Commented:
I don't actually want to rotate the type.  What I have is a series of columns, each with a shaded part up to a percentage of the total height.  In order to easily identify a click event on a particular column I have used labels instead of just drawing the columns, but now I can't print a short description down each label because the label control always overlay print controls on the form and the text goes to the back.

The text should go down vertically like:

You can make a text box look just like a label by turning off the border, etc. Set your alignment to centered and multiline to true. Then feed in your text as in:

Text1.Text = "T" & vbCRLF & "A" & vbCRLF & "R" ...

While in the development environment set the ZOrder to bring it to the front.


You can set the text box's multiline property to true and have the width to be one letter wide, you will get that.
after open the question, someone called me so I did not see the posted answer, sorry.

TaranadillaAuthor Commented:
This would have been a good answer but the reason I am trying to print over the top of the labels is that the text needs to be independant of the labels lying below it.  I will attemp to explain why but its a difficult concept to describe without a diagram:-

When you lie two labels (or text boxes) together and the text needs to follow on from one to the other without any interruption there is a problem that if the one label finshes part way through a letter then you might end up with half an "A" - and A with the legs cut off.  You then start the text again on the label/textbox adjoining it and it is impossible to start with just the legs of an "A" you need to start from the top with a whole character.

This is why I am trying to overlay text using the forms print property, but the way VB seems to work is to always put the controls on top.  I am really looking for a way of changing this.
TaranadillaAuthor Commented:
see above comment
Have you checked the autosize feature of the label? This might solve your cut-off problems.
TaranadillaAuthor Commented:
I am unable to size the labels at convenient sizes for the text - the two labels together have to be a given height and this height is divided between them at any possible percentage. therefore I cant use the autosize property
So the two labels together have a fixed height.
Are you able to change the height of each label?
TaranadillaAuthor Commented:
The labels together make a fixed height.  One is coloured the other not.  Together they form a partly filled box - the coloured part is to represent a percentage of the total height - it can be any percentage - in other words I have no control over deciding the height of either of the two parts of the box
TaranadillaAuthor Commented:
Sorry to sound dim but does this mean you can have a text box that is totally  transparent except for its text?

ie would I be able to see the two labels underneath, which is the effect I want

Believe so. Give it a shot.
TaranadillaAuthor Commented:
I can find backstyle property on label controls but not text box controls.  I have therefore
tried setting the backstyle of the labels to transparent and am getting some very unpredictable results.

The first time I (at run-time) load a pair of labels on the form they overwrite any text on the form that is behind them.  If I load a second pair of labels the text behind the original pair of labels becomes visible and the text behind the second pair of labels is obscured.  If I load another set of labels the text behind the second  pair of labels becomes visible but the new set obscure the text behind them

Is this something to do with the Zorder?  I looked this up in the help but am none the wiser - it seemed to say you could only change the display order of things on the same level as each other.
You can use "bring to front" to control order that controls render in.


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.

All Courses

From novice to tech pro — start learning today.