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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing multiple colors in one line

Status
Not open for further replies.

CyChosis

Programmer
Jan 16, 2003
5
0
0
US
This sounds simple, but it's not. How do I print out multiple colors on one line (through VB6)? For instance:
I want to make a line like this!
I've tried several different methods and none have worked so far. I need to be able to do this through a printer for sure, and it would be nice if I could do this on a picture box or some other control as well to give them a preview of what it will look like.
Help! This seems like such a ridiculous problem, but it's a pain to find a work around.
 
Add the Microsoft RichTextBox component to your project, drop an instance onto your form, then insert the following code into Form_Load():

Private Sub Form_Load()
With RichTextBox1
.Text = "This is a test of multiple colors"
.SelStart = 1
.SelLength = 4
.SelColor = vbRed
.SelStart = 5
.SelLength = 5
.SelColor = vbGreen
.SelStart = 11
.SelLength = 4
.SelColor = vbYellow
End With
End Sub
 
Thanks, guys. The richtextbox will allow me to easily display the information that I need to convey onscreen. How might I accomplish this through the printer though? That is still my top priority. I noticed the richtextbox contained
.selprint(IDHC as long, [vStartDoc])
might this be the solution, or is there a printer.method? Do you know what they mean by IDHC, or what I would enter?
 
I know this thread was sometime ago, but did you get it to work?
I am having the same problem when trying to print (using the Printer object) line by line and need to show some figures in red, some in yellow. Most are default blank on white!
 
If you are printing line by line you can use:

Printer.ForeColor = vbRed
Printer.Print "Experience is ";
Printer.ForeColor = vbYellow
Printer.Print "something you don't get ";
Printer.ForeColor = vbBlue
Printer.Print "until just after ";
Printer.ForeColor = vbBlack
Printer.Print "you need it."
Printer.EndDoc

Experience is something you don't get until just after you need it.
 
I've tried the above and it allows me to print the text in various colours. However, it doesn't allow me to vary the background. Ideally, I'd like to print black text over a yellow background.
Any ideas?
 
The only way I know how you might achieve this is messy and long winded.

First you need to set the printer.forecolor to what you want the background color to be. Probably using RGB to get best results.

Then set Printer.DrawWidth = 100 (or whatever suits your font size)

Write the Printer.currentX & Y to variables

Print a line with Printer.Line using Printer.CurrentX & Printer.currentY as co-ordinates.

Move print head back to the starting position with Printer.currentX = myvariable etc

Change your forecolor to the desired font color and print your text.

Repeat the process until you have printed all the line.

If I were you I would buy some coloured paper!




Experience is something you don't get until just after you need it.
 
simonkue

I have just been playing around with a much simpler solution which may be acceptable. You could print your text with a shadow effect using negative (or positive) values for currentX and Y.

Something like:

x = Printer.currentX
y = Printer.currentY
Printer.forecolor = vbyellow

Printer.Print "My text"

Printer.currentX = x - 20
Printer.currentY = y - 20
Printer.forecolor = vbBlack

Printer.print "My text"

Printer.enddoc

Experience is something you don't get until just after you need it.
 
bigalbigal,

Thanks for your help.
I've tried the last suggestion - the overprint and the effect is that the second line wipes out whatever is underneath it. Should I have some sort of "Transparent" selection???!

Here is the test code I'm using:

Printer.ColorMode = vbPRCMColor

xsOutline = ""
xsOutline = QLinePos(xsOutline, 5)
xsOutline = xsOutline & " Printer colour test output "
Printer.Print xsOutline

xnX = Printer.CurrentX
xnY = Printer.CurrentY

xnForecolour = Printer.ForeColor
Printer.ForeColor = vbRed
Printer.Print "Line 01 ############### "

Printer.CurrentX = xnX
Printer.CurrentY = xnY
Printer.ForeColor = xnForecolour
Printer.Print " 2 1234 "


The idea is that I should see "Line 012" at the beginning of the line with "Line 01" in red.
What I actually see is only the second line (in black) - as if the first had been overwritten with the spaces not being transparent but opaque.
Any suggestions?
 
A few points.

Firstly you didn't apply a negative or positive value to
Printer.CurrentX = xnX
Printer.CurrentY = xnY

You need to add an offset such as:
Printer.CurrentX = xnX - 20
Printer.CurrentY = xnY - 20

Secondly the second line of text should be exactly the same as the first line:

Printer.Print "Line 012 ############### "
Printer.Print "Line 012 ############### "

Thirdly you are setting xnForecolour unnecessarily:
xnForecolour = Printer.ForeColor

I would just use a direct statement as 'Printer.ForeColor = vbRed'



Experience is something you don't get until just after you need it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top