Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print text on top of a coloured background

Status
Not open for further replies.

Blobtech

Programmer
Dec 19, 2002
28
GB
Hi,

I'm using the Printer object to output some columns of data. For the column header I want to have a different coloured background. To do this I am using the Line command to draw a filled rectangle, then I'm printing the text on top.

It looks like I've got the Fillstyle parameter mixed up, because the background box is printing, but it looks like the text has it's own white background which is overlaying the background colour. I have tried several ways of doing this but nothing seems to work.

Can anyone point me in the right direction to do this?

Thanks in advance
 
This may help;

Public Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Public Const TRANSPARENT = 1
Public Const OPAQUE = 2


'usage; just before you begin printing
SetBkMode Printer.hdc, TRANSPARENT 'otherwise text may print with solid background
 
Here's the function I wrote

Function outBox(top, left, dataW, dataT, Optional dataA As Integer, Optional fontName As String, Optional fontSize As Integer, Optional boxColor As Long, Optional fillBox As Boolean)
'DataW is the width of the box, dataT is the text to print on/in the box. dataA is the alignment, 0=left, 1=right, 2=centre

If fontName = "" Then
Printer.Font.Name = Form1.Font.Name
Else
Printer.Font.Name = fontName
End If
If fontSize <> 0 Then Printer.Font.Size = fontSize Else Printer.Font.Size = 10

If fillBox = False Then
Printer.FillStyle = vbFSTransparent
Printer.Line (left, top)-(left + dataW, top + 5), boxColor, B
Else
Printer.FillStyle = vbFSSolid
Printer.FillColor = boxColor
Printer.Line (left, top)-(left + dataW, top + 5), , B
End If

If dataA = 0 Then Printer.CurrentX = left + 1
If dataA = 1 Then Printer.CurrentX = left + dataW - Printer.TextWidth(dataT) - 1
If dataA = 2 Then Printer.CurrentX = left + (dataW / 2) - (Printer.TextWidth(dataT) / 2)
Printer.CurrentY = top + 2.5 - (Printer.TextHeight(dataT) / 2)

Printer.ForeColor = vbBlack: Printer.Print dataT

Printer.FillStyle = vbFSTransparent
Printer.FillColor = vbWhite

End Function

The above function prints some text inside a box, or on top of a filled box
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top