Hi,
Sorry. I didnt get right back to you yesterday. Here is a improved
method. Draws on bitmap and set pictureboxes image to the bitmap so it will
automatically redraw. Alternate method to convert to twips is to multiply by
1440/ g.dpix.
Public Sub PrintRTF(ByRef RTF As RichTextBox, ByRef PB As
System.Windows.Forms.PictureBox)
Dim fr As FormatRange
Dim rcDrawTo As Rect
Dim rcPage As Rect
Dim TextLength As Integer
Dim NextCharPosition As Integer
Dim r As Integer
Dim bm As New Bitmap(PB.Width, PB.Height)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
Dim intScaleX As Single = 1440 / g.DpiX
Dim intScaleY As Single = 1440 / g.DpiY
Dim hdc As IntPtr = g.GetHdc
' Start a print job to get a valid PB.hDC
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = (PB.ClientRectangle.Width)
rcPage.Bottom = (PB.ClientRectangle.Height)
' Set rect in which to print (relative to printable area)
rcDrawTo.Left = 0
rcDrawTo.Top = 0
rcDrawTo.Right = PB.Width * intScaleX
rcDrawTo.Bottom = PB.Height * intScaleY
' Set up the print instructions
fr.hdc = hdc.ToInt32 ' Use the same DC for measuring and rendering
fr.hdcTarget = hdc.ToInt32 ' Point at printer hDC
fr.rc = rcDrawTo ' Indicate the area on page to draw to
fr.rcPage = rcPage ' Indicate entire size of page
fr.chrg.cpMin = 0 ' Indicate start of text through
fr.chrg.cpMax = -1 ' end of the text
' Get length of text in RTF
TextLength = RTF.Text.Length
' Loop printing each page until done
Do
' Print the page by sending EM_FORMATRANGE message
NextCharPosition = SendMessage(RTF.Handle, EM_FORMATRANGE, True, fr)
fr.chrg.cpMin = NextCharPosition ' Starting position for next page()
fr.hdc = hdc.ToInt32
fr.hdcTarget = hdc.ToInt32
Loop Until NextCharPosition >= TextLength
' Allow the RTF to free up memory
r = SendMessage(RTF.Handle, EM_FORMATRANGE, False, 0)
g.ReleaseHdc(hdc)
PB.Image = bm
End Sub
Public Sub PrintRTF(ByRef RTF As RichTextBox, ByRef PB As
System.Windows.Forms.PictureBox)
Dim fr As FormatRange
Dim rcDrawTo As Rect
Dim rcPage As Rect
Dim TextLength As Integer
Dim NextCharPosition As Integer
Dim r As Integer
Dim bm As New Bitmap(PB.Width, PB.Height)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(Color.White)
Dim intScaleX As Single = 1440 / g.DpiX
Dim intScaleY As Single = 1440 / g.DpiY
Dim hdc As IntPtr = g.GetHdc
' Start a print job to get a valid PB.hDC
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = (PB.ClientRectangle.Width)
rcPage.Bottom = (PB.ClientRectangle.Height)
' Set rect in which to print (relative to printable area)
rcDrawTo.Left = 0
rcDrawTo.Top = 0
rcDrawTo.Right = PB.Width * intScaleX
rcDrawTo.Bottom = PB.Height * intScaleY
' Set up the print instructions
fr.hdc = hdc.ToInt32 ' Use the same DC for measuring and rendering
fr.hdcTarget = hdc.ToInt32 ' Point at printer hDC
fr.rc = rcDrawTo ' Indicate the area on page to draw to
fr.rcPage = rcPage ' Indicate entire size of page
fr.chrg.cpMin = 0 ' Indicate start of text through
fr.chrg.cpMax = -1 ' end of the text
' Get length of text in RTF
TextLength = RTF.Text.Length
' Loop printing each page until done
Do
' Print the page by sending EM_FORMATRANGE message
NextCharPosition = SendMessage(RTF.Handle, EM_FORMATRANGE, True, fr)
fr.chrg.cpMin = NextCharPosition ' Starting position for next page()
fr.hdc = hdc.ToInt32
fr.hdcTarget = hdc.ToInt32
Loop Until NextCharPosition >= TextLength
' Allow the RTF to free up memory
r = SendMessage(RTF.Handle, EM_FORMATRANGE, False, 0)
g.ReleaseHdc(hdc)
PB.Image = bm
End Sub
Ken
-----------------
[quoted text, click to view] "Neal" <anonymous@discussions.microsoft.com> wrote in message
news:008501c3d344$70e923f0$a001280a@phx.gbl...
> Thank you, the reason that this was not apparent was that
> the width of the column in the References window was too
> narrow to see it properly.
>
> Neal
>>-----Original Message-----
>>Hi Neal,
>>
>>To use the VB6.TwipsToPixelsX, you may need to add a
> reference to Microsoft
>>Visual Basic .NET Compatibility Runtime.
>>and
>>Imports Microsoft.VisualBasic.Compatibility in your
> project.
>>
>>Here is an article, you may take a look.
>>ScaleMode is not supported
>>
http://msdn.microsoft.com/library/default.asp? > url=/library/en-us/vbcon/html/
>>vbup2038.asp
>>
>>If you have any concern on this issue, please post here.
>>
>>Regards,
>>Peter Huang
>>Microsoft Online Partner Support
>>Get Secure!
www.microsoft.com/security >>This posting is provided "as is" with no warranties and
> confers no rights.
>>
>>.
>>