需要在VB.NET中将RTF文本打印到PictureBox中 [英] Need to print out RTF text into a PictureBox in VB.NET

查看:62
本文介绍了需要在VB.NET中将RTF文本打印到PictureBox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在这个链接上看到了VB6代码:

http://www.dotnet247.com/247referenc.../11/56581.aspx


VB6代码如下:


私有类型Rect

剩余长期

Top To Long

正确长期

底部长期

结束类型


私人类型CharRange

cpMin As Long''范围的第一个字符(0开头为

doc)

cpMax As Long''范围的最后一个字符( -1结束

doc)

结束类型


私有类型FormatRange

hdc As很长的''实际DC可以借用

hdcTarget As Long''Target DC用于确定文本

格式化

rc As Rect''Region of绘制的DC(以缇为单位)

rcPage As Rect''整个DC的区域(页面大小)(i n $ /
twips)

chrg作为CharRange''要绘制的文字范围(见上文

声明)

结束类型


Private Const WM_USER As Long =& H400

Private Const EM_FORMATRANGE Long = WM_USER + 57


私有声明函数SendMessage Lib" USER32"

Alias" SendMessageA"
_

(ByVal hWnd As Long,ByVal msg As很长,ByVal wp As Long,

_

lp As Any)As Long


Public Sub PrintRTF(RTF As RichTextBox, PB作为PictureBox)


Dim fr As FormatRange

Dim rcDrawTo As Rect

Dim rcPage As Rect

Dim TextLength As Long

Dim NextCharPosition As Long

Dim r As Long


''开始打印作业一个有效的PB.hDC

PB.Cls

PB.ScaleMode = vbTwips


''计算左,上,右和底部边缘


''设置可打印区域rect

rcPage.Left = 0

rcPage.Top = 0

rcPage.Right = PB.ScaleWidth

rcPage.Bottom = PB.ScaleHeight


''设置要打印的矩形(相对于可打印区域)

rcDrawTo.Left = 0

rcDrawTo.Top = 0

rcDrawTo.Right = PB.Width

rcDrawTo.Bottom = PB.Height


''设置打印说明

fr.hdc = PB.hdc''使用相同的DC进行测量和

渲染

fr.hdcTarget = PB.hdc''指向打印机hDC

fr.rc = rcDrawTo''指明要绘制的页面区域

fr.rcPage = rcPage ''表示页面的整个大小

fr.chrg.cpMin = 0''表示文本的开头通过

fr.chrg.cpMax = -1''结束文本


''以RTF格式获取文本长度

TextLength = Len(RTF.Text)


' '循环打印每页直到完成



''通过发送EM_FORMATRANGE消息打印页面

NextCharPosition = SendMessage(RTF.hWnd,EM_FORMATRANGE,

True,

fr )

如果NextCharPosition> = TextLength然后退出Do''如果完成

那么

退出

fr。 chrg.cpMin = NextCharPosition''起始位置

下一页




fr.hdc = PB.hdc
fr.hdcTarget = PB.hdc

循环


''允许RTF释放内存

r = SendMessage(RTF.hWnd,EM_FORMATRANGE,False,ByVal

CLng(0))


结束子

做了哪些更改我需要将这个代码移植到

VB.NET?


谢谢,


Neal

解决方案

对于VB.NET或C#,你需要使用GDI +在图片框上绘图。


-

Dhaval Faria

创始人,程序员

Hirdhav( http://www.hirdhav.com

微软印度社区之星

Neal <是ne ** @ milsys.com>在消息中写道

news:04 **************************** @ phx.gbl ... < blockquote class =post_quotes>

我在这个链接上看到了VB6代码:

http://www.dotnet247.com/247referenc.../11/56581.aspx

VB6代码内容如下:

私人类型Rect
Left As Long
Top To Long
Right As Long
Bottom As长期

私人类型CharRange
cpMin为长''范围的第一个字符(0为开始
doc)
cpMax As Long' '范围的最后一个字符(
doc结束时为-1)
结束类型

私有类型FormatRange
hdc为'长''实际DC绘制
hdcTarget As Long''用于确定文本的目标DC
格式化
rc As Rect''要绘制的DC区域(以缇为单位)
rcPage As Rect''整个区域DC(页面大小)(在
twips)
chrg作为CharRange''要绘制的文字范围(见上文
声明)
结束类型

私人Const WM_USER As Long =& H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57
私人声明功能SendMessage LibUSER32
AliasSendMessageA
_
( ByVal hWnd as Long,ByVal msg As Long,ByVal wp As Long,
_
lp As Any)As Long

公共子PrintRTF(RTF作为RichTextBox,PB作为PictureBox)

Dim fr As FormatRange
Dim rcDrawTo As Rect
Dim rcPage As Rect
Dim TextLength As Long
Dim NextCharPosition As Long
Dim r As Long

''开始打印作业以获得有效的PB.hDC
PB.Cls
PB.ScaleMode = vbTwips

''计算左边,上边,右边和下边距

''设置可打印区域rect
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = PB.ScaleWidth
rcPage.Bottom = PB.ScaleH八,
''设置矩形在哪里打印(相对于可打印区域)
rcDrawTo.Left = 0
rcDrawTo.Top = 0
rcDrawTo.Right = PB 。宽度
rcDrawTo.Bottom = PB.Height

''设置打印指令
fr.hdc = PB.hdc''使用相同的DC进行测量和
渲染
fr.hdcTarget = PB.hdc''指向打印机hDC
fr.rc = rcDrawTo''表示要绘制的页面区域
fr.rcPage = rcPage''指示页面的整个大小
fr.chrg.cpMin = 0''通过
fr.chrg.cpMax = -1''表示文本开头

' '以RTF格式获取文本长度
TextLength = Len(RTF.Text)

''循环打印每页直到完成
'
''打印页面发送EM_FORMATRANGE消息
NextCharPosition = SendMessage(RTF.hWnd,EM_FORMATRANGE,
True,
fr)
如果NextCharPosition> = TextLength则退出Do''如果完成
然后
退出 fr.chrg.cpMin = NextCharPosition''起始位置
下一页

fr.hdc = PB.hdc
fr.hdcTarget = PB.hdc <循环

''允许RTF释放内存
r = SendMessage(RTF.hWnd,EM_FORMATRANGE,False,ByVal
CLng(0))

End Sub

我需要对此代码进行哪些更改才能将其移植到VB.NET?

谢谢,
Neal



更具体一点。使用表单的CreateGraphics方法允许你在它上面绘制



Dim g as Graphics = FormName.CreateGraphics()
<问候 - OHM


Dhaval Faria写道:

对于VB.NET或C#,你需要使用GDI +来绘制图片盒子。

Neal <是ne ** @ milsys.com>在消息中写道
新闻:04 **************************** @ phx.gbl ...



我看到VB6代码在此链接上执行此操作:

http://www.dotnet247.com/247referenc.../11/56581.aspx
VB6代码内容如下:

私人类型Rect
Left As Long
Top To Long
Right As Long
Bottom As Long 结束类型

私有类型CharRange
cpMin为长''范围的第一个字符(0为
doc的开头)
cpMax As Long''的最后一个字符范围(-1为
doc结束)
结束类型

私有类型FormatRange
hdc为长''实际DC绘制
hdcTarget As Long''用于确定文本的目标DC
格式化
rc As Rect''要绘制的DC区域(以缇为单位)
rcPage As Rect''整个DC的区域(页面大小) )(在
中twips)
chrg作为CharRange''要绘制的文字范围(见上文
声明)
结束类型

私人Const WM_USER As Long =& H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57
私有声明函数SendMessage Lib" USER32"
AliasSendMessageA
_
(ByVal hWnd As很长,ByVal msg As Long,ByVal wp As Long,
_
lp As Any)As Long





公共子PrintRTF(RTF作为RichTextBox,PB作为PictureBox)

Dim fr As FormatRange
Dim rcDrawTo As Rect
Dim rcPage As Rect
Dim TextLength As Long
Dim NextCharPosition As Long
Dim r As Long

''开始打印作业以获得有效的PB.hDC
PB.Cls
PB.ScaleMode = vbTwips

''计算左边,顶部,右侧和底部边距

''设置可打印区域rect
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = PB.ScaleWidth
rcPage.Bottom = PB.ScaleHeight

''设置要打印的矩形(相对于可打印区域)
rcDrawTo.Left = 0
rcDrawTo.Top = 0
rcDrawTo.Right = PB。宽度
rcDrawTo.Bottom = PB.Height

''设置打印说明
fr.hdc = PB.hdc''使用相同的DC进行测量和
渲染
fr.hdcTarget = PB.hdc''指向打印机hDC
fr.rc = rcDrawTo''表示要绘制的页面区域
fr.rcPage = rcPage''表示页面的整个大小
fr.chrg.cpMin = 0''表示文本开头通过
fr.chrg.cpMax = -1''文本结尾

''以RTF格式获取文本长度
TextLength = Len(RTF.Text)

''循环打印每页直到完成
'
''通过发送打印页面EM_FORMATRANGE消息
NextCharPosition = SendMessage(RTF.hWnd,EM_FORMATRANGE,
True,
fr)
如果NextCharPosition> = TextLength则退出Do''如果完成
那么
退出
fr。 chrg.cpMin = NextCharPosition''起始位置
下一页

fr.hdc = PB.hdc
fr.hdcTarget = PB.hdc
循环

''允许RTF释放内存
r = SendMessage(RTF.hWnd,EM_FORMATRANGE,False,ByVal
CLng(0))
/>结束Sub

我需要对此代码进行哪些更改才能将其移植到VB.NET?

谢谢,

Neal




-

最诚挚的问候 - OHM


O_H_M {at} BTInternet {dot} com





给你。

声明函数SendMessage Lib" user32"别名SendMessageA _ $ />

(ByVal hwnd As IntPtr,ByVal wMsg As Integer,ByVal wParam as Integer,_


ByVal lParam As Integer)As Integer


声明函数SendMessage Lib" user32"别名SendMessageA _ $ />

(ByVal hwnd As IntPtr,ByVal wMsg as Integer,ByVal wParam as Integer,_


ByRef lParam As FormatRange)As Integer


公共结构Rect


向左调整整数


Dim Top as Integer


调整为整数


昏暗底部整数


结束结构


公共结构CharRange


Dim cpMin As Integer''范围的第一个字符(0表示开始doc)


Dim cpMax作为整数''范围的最后一个字符(-1结束文档)


结束结构


公共结构FormatRange


Dim hdc As Integer''实际DC用于


Dim hdcTarget As Integer''Target DC用于确定文本格式


Dim rc As Rect''要绘制的DC区域(以缇为单位)


Dim rcPage As Rect''整个DC的区域(页面大小)(缇)


Dim chrg作为CharRange''要绘制的文字范围(见上面的声明)


结束结构


私有Const WM_USER As Integer =& H400S


私有Const EM_FORMATRANGE As Integer = WM_USER + 57


公开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 g As Graphics = PB.CreateGraphics

g.Clear(Color.White)


Dim hdc As IntPtr = g.GetHdc


''开始打印获得有效的PB.hDC工作


rcPage.Left = 0

rcPage.Top = 0


rcPage.Right = PB.ClientRectangle.Width

rcPage.Bottom = PB.ClientRectangle.Height


''设置要打印的矩形(相对于可打印区域)


rcDrawTo.Left = 0


rcDrawTo.Top = 0

rcDrawTo.Right = VB6.PixelsToTwipsX(PB.Width)


rcDrawTo.Bottom = VB6.PixelsToTwipsY(PB.Height)


''设置打印说明


fr.hdc = hdc .ToInt32''使用相同的DC进行测量和渲染


fr.hdcTarget = hdc.ToInt32''指向打印机hDC


fr .rc = rcDrawTo''表示要绘制的页面区域


fr.rcPage = rcPage''表示整页大小


fr.chrg.cpMin = 0''通过


fr.chrg.cpMax = -1''表示文本开头


''以RTF格式获取文本长度

TextLength = RTF.Text.Length


''循环打印每页直到完成





''通过发送EM_FORMATRANGE消息打印页面


NextCharPosition = SendMessage(RTF.Handle,EM_FORMATRANGE,True,fr)

>
如果NextCharPosition> = TextLength然后退出做


fr.chrg.cpMin = NextCharPosition''下一页的起始位置()


fr.hdc = hdc.ToInt32

fr.hdcTarget = hdc.ToInt32


循环

''允许RTF释放内存


r = SendMessage(RTF.Handle,EM_FORMATRANGE,False,0)


g.ReleaseHdc(hdc)


结束子





---- -------------------------


Hi,

I saw the VB6 Code to do this at this link:

http://www.dotnet247.com/247referenc.../11/56581.aspx

The VB6 Code reads as follows:

Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type CharRange
cpMin As Long '' First character of range (0 for start of
doc)
cpMax As Long '' Last character of range (-1 for end of
doc)
End Type

Private Type FormatRange
hdc As Long '' Actual DC to draw on
hdcTarget As Long '' Target DC for determining text
formatting
rc As Rect '' Region of the DC to draw to (in twips)
rcPage As Rect '' Region of the entire DC (page size) (in
twips)
chrg As CharRange '' Range of text to draw (see above
declaration)
End Type

Private Const WM_USER As Long = &H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57

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

Public Sub PrintRTF(RTF As RichTextBox, PB As PictureBox)

Dim fr As FormatRange
Dim rcDrawTo As Rect
Dim rcPage As Rect
Dim TextLength As Long
Dim NextCharPosition As Long
Dim r As Long

'' Start a print job to get a valid PB.hDC
PB.Cls
PB.ScaleMode = vbTwips

'' Calculate the Left, Top, Right, and Bottom margins

'' Set printable area rect
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = PB.ScaleWidth
rcPage.Bottom = PB.ScaleHeight

'' Set rect in which to print (relative to printable area)
rcDrawTo.Left = 0
rcDrawTo.Top = 0
rcDrawTo.Right = PB.Width
rcDrawTo.Bottom = PB.Height

'' Set up the print instructions
fr.hdc = PB.hdc '' Use the same DC for measuring and
rendering
fr.hdcTarget = PB.hdc '' 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 = Len(RTF.Text)

'' Loop printing each page until done
Do
'' Print the page by sending EM_FORMATRANGE message
NextCharPosition = SendMessage(RTF.hWnd, EM_FORMATRANGE,
True,
fr)
If NextCharPosition >= TextLength Then Exit Do ''If done
then
exit
fr.chrg.cpMin = NextCharPosition '' Starting position for
next
page

fr.hdc = PB.hdc
fr.hdcTarget = PB.hdc
Loop

'' Allow the RTF to free up memory
r = SendMessage(RTF.hWnd, EM_FORMATRANGE, False, ByVal
CLng(0))

End Sub
What changes do I need to make to this code to port it to
VB.NET?

Thanks,

Neal

解决方案

for VB.NET or C#, you require to use GDI+ to draw on picture box.

--
Dhaval Faria
Founder, Programmer
Hirdhav (http://www.hirdhav.com)
Microsoft India Community Star
"Neal" <ne**@milsys.com> wrote in message
news:04****************************@phx.gbl...

Hi,

I saw the VB6 Code to do this at this link:

http://www.dotnet247.com/247referenc.../11/56581.aspx

The VB6 Code reads as follows:

Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type CharRange
cpMin As Long '' First character of range (0 for start of
doc)
cpMax As Long '' Last character of range (-1 for end of
doc)
End Type

Private Type FormatRange
hdc As Long '' Actual DC to draw on
hdcTarget As Long '' Target DC for determining text
formatting
rc As Rect '' Region of the DC to draw to (in twips)
rcPage As Rect '' Region of the entire DC (page size) (in
twips)
chrg As CharRange '' Range of text to draw (see above
declaration)
End Type

Private Const WM_USER As Long = &H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57

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

Public Sub PrintRTF(RTF As RichTextBox, PB As PictureBox)

Dim fr As FormatRange
Dim rcDrawTo As Rect
Dim rcPage As Rect
Dim TextLength As Long
Dim NextCharPosition As Long
Dim r As Long

'' Start a print job to get a valid PB.hDC
PB.Cls
PB.ScaleMode = vbTwips

'' Calculate the Left, Top, Right, and Bottom margins

'' Set printable area rect
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = PB.ScaleWidth
rcPage.Bottom = PB.ScaleHeight

'' Set rect in which to print (relative to printable area)
rcDrawTo.Left = 0
rcDrawTo.Top = 0
rcDrawTo.Right = PB.Width
rcDrawTo.Bottom = PB.Height

'' Set up the print instructions
fr.hdc = PB.hdc '' Use the same DC for measuring and
rendering
fr.hdcTarget = PB.hdc '' 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 = Len(RTF.Text)

'' Loop printing each page until done
Do
'' Print the page by sending EM_FORMATRANGE message
NextCharPosition = SendMessage(RTF.hWnd, EM_FORMATRANGE,
True,
fr)
If NextCharPosition >= TextLength Then Exit Do ''If done
then
exit
fr.chrg.cpMin = NextCharPosition '' Starting position for
next
page

fr.hdc = PB.hdc
fr.hdcTarget = PB.hdc
Loop

'' Allow the RTF to free up memory
r = SendMessage(RTF.hWnd, EM_FORMATRANGE, False, ByVal
CLng(0))

End Sub
What changes do I need to make to this code to port it to
VB.NET?

Thanks,

Neal



To be more specific. Use the CreateGraphics method of the form to allow you
to draw on it.

Dim g as Graphics = FormName.CreateGraphics()

Regards - OHM

Dhaval Faria wrote:

for VB.NET or C#, you require to use GDI+ to draw on picture box.
"Neal" <ne**@milsys.com> wrote in message
news:04****************************@phx.gbl...

Hi,

I saw the VB6 Code to do this at this link:

http://www.dotnet247.com/247referenc.../11/56581.aspx

The VB6 Code reads as follows:

Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type CharRange
cpMin As Long '' First character of range (0 for start of
doc)
cpMax As Long '' Last character of range (-1 for end of
doc)
End Type

Private Type FormatRange
hdc As Long '' Actual DC to draw on
hdcTarget As Long '' Target DC for determining text
formatting
rc As Rect '' Region of the DC to draw to (in twips)
rcPage As Rect '' Region of the entire DC (page size) (in
twips)
chrg As CharRange '' Range of text to draw (see above
declaration)
End Type

Private Const WM_USER As Long = &H400
Private Const EM_FORMATRANGE As Long = WM_USER + 57

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

Public Sub PrintRTF(RTF As RichTextBox, PB As PictureBox)

Dim fr As FormatRange
Dim rcDrawTo As Rect
Dim rcPage As Rect
Dim TextLength As Long
Dim NextCharPosition As Long
Dim r As Long

'' Start a print job to get a valid PB.hDC
PB.Cls
PB.ScaleMode = vbTwips

'' Calculate the Left, Top, Right, and Bottom margins

'' Set printable area rect
rcPage.Left = 0
rcPage.Top = 0
rcPage.Right = PB.ScaleWidth
rcPage.Bottom = PB.ScaleHeight

'' Set rect in which to print (relative to printable area)
rcDrawTo.Left = 0
rcDrawTo.Top = 0
rcDrawTo.Right = PB.Width
rcDrawTo.Bottom = PB.Height

'' Set up the print instructions
fr.hdc = PB.hdc '' Use the same DC for measuring and
rendering
fr.hdcTarget = PB.hdc '' 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 = Len(RTF.Text)

'' Loop printing each page until done
Do
'' Print the page by sending EM_FORMATRANGE message
NextCharPosition = SendMessage(RTF.hWnd, EM_FORMATRANGE,
True,
fr)
If NextCharPosition >= TextLength Then Exit Do ''If done
then
exit
fr.chrg.cpMin = NextCharPosition '' Starting position for
next
page

fr.hdc = PB.hdc
fr.hdcTarget = PB.hdc
Loop

'' Allow the RTF to free up memory
r = SendMessage(RTF.hWnd, EM_FORMATRANGE, False, ByVal
CLng(0))

End Sub
What changes do I need to make to this code to port it to
VB.NET?

Thanks,

Neal



--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


Hi,

Here you go.
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _

(ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, _

ByVal lParam As Integer) As Integer

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _

(ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, _

ByRef lParam As FormatRange) As Integer

Public Structure Rect

Dim Left As Integer

Dim Top As Integer

Dim Right As Integer

Dim Bottom As Integer

End Structure

Public Structure CharRange

Dim cpMin As Integer '' First character of range (0 for start of doc)

Dim cpMax As Integer '' Last character of range (-1 for end of doc)

End Structure

Public Structure FormatRange

Dim hdc As Integer '' Actual DC to draw on

Dim hdcTarget As Integer '' Target DC for determining text formatting

Dim rc As Rect '' Region of the DC to draw to (in twips)

Dim rcPage As Rect '' Region of the entire DC (page size) (in twips)

Dim chrg As CharRange '' Range of text to draw (see above declaration)

End Structure

Private Const WM_USER As Integer = &H400S

Private Const EM_FORMATRANGE As Integer = WM_USER + 57

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 g As Graphics = PB.CreateGraphics

g.Clear(Color.White)

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 = VB6.PixelsToTwipsX(PB.Width)

rcDrawTo.Bottom = VB6.PixelsToTwipsY(PB.Height)

'' 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)

If NextCharPosition >= TextLength Then Exit Do

fr.chrg.cpMin = NextCharPosition '' Starting position for next page()

fr.hdc = hdc.ToInt32

fr.hdcTarget = hdc.ToInt32

Loop

'' Allow the RTF to free up memory

r = SendMessage(RTF.Handle, EM_FORMATRANGE, False, 0)

g.ReleaseHdc(hdc)

End Sub

Ken

-----------------------------


这篇关于需要在VB.NET中将RTF文本打印到PictureBox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆