Solved

Overlaying labels with text

Posted on 1998-10-13
17
265 Views
Last Modified: 2010-04-30
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
0
Comment
Question by:Taranadilla
  • 7
  • 4
  • 3
  • +2
17 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1439708
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?
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1439709
Taranadilla,
It looked to me you want to print some text vertically.
Here is the code to do that.
Regards
Dalin



       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(LF_FACESIZE) As Byte 'THIS WAS DEFINED IN API-CHANGES MY OWN
         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

       Trap:

       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


0
 

Author Comment

by:Taranadilla
ID: 1439710
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:

T
A
R
A
N
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1439711
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.

M


0
 
LVL 9

Expert Comment

by:Dalin
ID: 1439712
You can set the text box's multiline property to true and have the width to be one letter wide, you will get that.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1439713
after open the question, someone called me so I did not see the posted answer, sorry.

0
 

Author Comment

by:Taranadilla
ID: 1439714
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.
0
 

Author Comment

by:Taranadilla
ID: 1439715
see above comment
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 13

Expert Comment

by:Mirkwood
ID: 1439716
Have you checked the autosize feature of the label? This might solve your cut-off problems.
0
 

Author Comment

by:Taranadilla
ID: 1439717
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
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1439718
So the two labels together have a fixed height.
Are you able to change the height of each label?
0
 

Author Comment

by:Taranadilla
ID: 1439719
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
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 200 total points
ID: 1439720
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.

M

0
 

Author Comment

by:Taranadilla
ID: 1439721
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

0
 
LVL 12

Expert Comment

by:mark2150
ID: 1439722
Believe so. Give it a shot.
0
 

Author Comment

by:Taranadilla
ID: 1439723
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.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1439724
You can use "bring to front" to control order that controls render in.

M

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now