Link to home
Start Free TrialLog in
Avatar of lungwa
lungwa

asked on

printing in VB

I am the newbie in VB how can I print a text file in printer and some text i want to bold it before print out ?????
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want to format text, you'll have to use the richtextbox

To make selected text bold, underlined, italic or strikethrough you can use the following code:

Statement Action
RichTextBox1.SelBold = True Makes the selected text Bold
RichTextBox1.SelItalic = True Makes the selected text Italic
RichTextBox1.SelUnderline = True Makes the selected text Underlined
RichTextBox1.SelStrikeThru = True Makes the selected text Strikethrough

To change the alignment, simply use this syntax:

RichTextBox1.SelAlignment = Alignment

Where alignment is one of the following constants:

Constant Alignment
vbRight Right
vbLeft Left
vbCenter Centre

So, the following code will set make the selected text underlined, and aligned to the right.

RichTextBox1.SelAlignment = vbRight
RichTextBox1.SelUnderline = True



To print out a formatted richtextbox:

'Name of Rich Text Box Control = rtf
'Write this code under Print Button

rtf.SelPrint Printer.hDC
rtf.SelStart = lastposition
rtf.SelLength = lastSelection
They are right. As the first example load the text into a richTextBox. You can keep the richtextbox hidden if you like so. Then lets say you want to make all numbers Bold. Use a loop to go through each character... then use this:
if isNumeric(charac ) then    'or if charac="important letter"
rtb.selstart=ind
rtb.SelBold = True
end if