|
-
Nov 8th, 2004, 04:11 AM
#1
Thread Starter
Fanatic Member
Printing Bold
HI All,
I have this function that sets the contents of a Rich text box to bold and sets some of the text red, What I want to know is how can I print the contents of the Rich text box as it is seen in my program (Bold and red)? as at the moment it prints it all out as normal text.
VB Code:
Private Sub Show_Failed_Conversions()
Dim currentnumber As Long
Dim newnum As Integer
Dim oldnum As Integer
Dim FindBracket As Integer
'Add time and data to the log file
frmQConversion.txtLogFails.Text = "Time: " & Format$(Now, "hh:mm:ss") & vbCrLf & "Date: " & Format$(Now, "dd/mm/yy") & vbCrLf & vbCrLf
'Loop though the collection and add items to the log file
For currentnumber = 1 To holder.Count Step 1
frmQConversion.txtLogFails.Text = frmQConversion.txtLogFails.Text & holder(currentnumber) & holdName(currentnumber) & " to " & HoldMe(currentnumber) & vbCrLf
frmQConversion.txtLogFails.SelStart = 0
frmQConversion.txtLogFails.SelLength = Len(frmQConversion.txtLogFails.Text)
frmQConversion.txtLogFails.SelBold = True
Next currentnumber
newnum = 1
oldnum = 2
For FindBracket = 1 To Len(frmQConversion.txtLogFails.Text) Step 2
oldnum = InStr(oldnum, frmQConversion.txtLogFails.Text, "[")
newnum = InStr(newnum, frmQConversion.txtLogFails.Text, "]")
If oldnum = 0 Then
Exit For
Else
frmQConversion.txtLogFails.SelStart = oldnum - 1
frmQConversion.txtLogFails.SelLength = (newnum - oldnum + 1)
frmQConversion.txtLogFails.SelBold = True
frmQConversion.txtLogFails.SelColor = vbRed
oldnum = newnum + 1
newnum = newnum + 2
End If
Next FindBracket
'Clear the collection
Set holder = Nothing
Set holdName = Nothing
Set HoldMe = Nothing
End Sub
And here is where im printing it.
VB Code:
Private Sub cmbPrintLog_Click()
Printer.Print txtLogFails.Text
Printer.EndDoc
End Sub
Thanks
Loftty
-
Nov 8th, 2004, 04:58 AM
#2
Banned
use a richtextbox and in that amke text bold .... i dont know if that wuld work
-
Nov 8th, 2004, 05:20 AM
#3
Lively Member
Hi mate,
I think the problem is that you are saving to a .txt file which will not preserve the formatting from the RichTextBox. Try saving as .rtf or .doc and print those.
All the best,
Dave.
-
Nov 8th, 2004, 05:56 AM
#4
Thread Starter
Fanatic Member
Hi Dave,
I'm not saving the file all I want to do is print the contents of the Rich text box.
Loftty
-
Nov 8th, 2004, 06:17 AM
#5
I saw this on the web. I have not tried it:
VB Code:
' #VBIDEUtils#*********************************************
' * Programmer Name : Waty Thierry
' * Web Site : [url]www.geocities.com/ResearchTriangle/6311/[/url]
' * Date : 28/06/99
' * Time : 13:01
' ************************************************************
' * Comments : Print RichTextBox contents
' *
' *
' ***************************************************************
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal msg As Long, _
ByVal wp As Long, lp As Any) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Const WM_USER = &H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type CharRange
cpMin As Long
cpMax As Long
End Type
Private Type FormatRange
hdc As Long
hdcTarget As Long
rc As RECT
rcPage As RECT
chrg As CharRange
End Type
VB Code:
Public Function PrintRTF(rtf As RichTextBox, nnLeftMarginWidth _
As Long, nnTopMarginHeight As Long, nnRightMarginWidth As _
Long, nnBottomMarginHeight As Long) As Boolean
' #VBIDEUtils#************************************************
' * Programmer Name : Waty Thierry
' * Web Site : [url]www.geocities.com/ResearchTriangle/6311/[/url]
' * Date : 30/10/98
' * Time : 14:43
' * Module Name : Main_Module
' * Module Filename : Main.bas
' * Procedure Name : PrintRTF
' * Parameters :
' * rtf As RichTextBox
' * nnLeftMarginWidth As Long
' * nnTopMarginHeight As Long
' * nnRightMarginWidth As Long
' * nnBottomMarginHeight As Long
' ***************************************************************
' * Comments :
' *
' *
' *************************************************************
On Error GoTo ErrorHandler
Dim nLeftOffset As Long
Dim nTopOffset As Long
Dim nLeftMargin As Long
Dim nTopMargin As Long
Dim nRightMargin As Long
Dim nBottomMargin As Long
Dim fr As FormatRange
Dim rcDrawTo As RECT
Dim rcPage As RECT
Dim nTextLength As Long
Dim nNextCharPos As Long
Dim nRet As Long
Printer.Print Space(1)
Printer.ScaleMode = vbTwips
nLeftOffset = Printer.ScaleX(GetDeviceCaps(Printer.hdc, _
PHYSICALOFFSETX), vbPixels, vbTwips)
nTopOffset = Printer.ScaleY(GetDeviceCaps(Printer.hdc, _
PHYSICALOFFSETY), vbPixels, vbTwips)
nLeftMargin = nnLeftMarginWidth - nLeftOffset
nTopMargin = nnTopMarginHeight - nTopOffset
nRightMargin = (Printer.Width - nnRightMarginWidth) _
- nLeftOffset
nBottomMargin = (Printer.Height - nnBottomMarginHeight) _
- nTopOffset
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = Printer.ScaleWidth
rcPage.Bottom = Printer.ScaleHeight
rcDrawTo.Left = nLeftMargin
rcDrawTo.Top = nTopMargin
rcDrawTo.Right = nRightMargin
rcDrawTo.Bottom = nBottomMargin
fr.hdc = Printer.hdc
fr.hdcTarget = Printer.hdc
fr.rc = rcDrawTo
fr.rcPage = rcPage
fr.chrg.cpMin = 0
fr.chrg.cpMax = -1
nTextLength = Len(rtf.Text)
Do
fr.hdc = Printer.hdc
fr.hdcTarget = Printer.hdc
nNextCharPos = SendMessage(rtf.hWnd, EM_FORMATRANGE, _
True, fr)
If nNextCharPos >= nTextLength Then Exit Do
fr.chrg.cpMin = nNextCharPos
Printer.NewPage
Printer.Print Space(1)
Loop
Printer.EndDoc
nRet = SendMessage(rtf.hWnd, EM_FORMATRANGE, _
False, ByVal CLng(0))
PrintRTF = True
Exit Function
ErrorHandler:
PrintRTF = False
End Function
-
Nov 9th, 2004, 04:09 AM
#6
Lively Member
Hi loftty,
Sorry mate (note to self: Learn to read the code properly before posting).
Have you tried using the .selprint method of the richtextbox?
VB Code:
RichTextBox1.SelPrint (Printer.hDC)
I've only had a quick go with it but it seems to preserve the formatting.
All the best,
Dave.
-
Nov 9th, 2004, 06:57 AM
#7
Thread Starter
Fanatic Member
Hi Dave,
It does print it out bold but it only prints out the first line, then when I hit print again it prints the whole RTF. what would be wrong?
Thanks
Loftty
-
Nov 9th, 2004, 08:56 AM
#8
Lively Member
Weird!!!
Can you re-post the code?
Dave.
-
Nov 10th, 2004, 04:13 AM
#9
Thread Starter
Fanatic Member
Hi Dave,
Here is the code where I print
VB Code:
Private Sub cmbPrintLog_Click()
txtLogFails.SelPrint (Printer.hDC)
End Sub
The other code is in the first message.
Thanks
Loftty
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|