基本方法

PDFCreator并不存在表格的概念,所有的表格都是通过逐个单元格绘制出来的,所以我们先介绍一下相关方法。

DrawRectangle

DrawRectangle用于绘制一个四边形,其的语法为:

DrawRectangle(pen, rect)
DrawRectangle(pen, rect, corners)
DrawRectangle(pen, x, y, width, height)

参数 说明
pen 指定用于绘制四边形边框的画笔。

通过Pens集合可以获得各种颜色的画笔,例如:

Dim pn As Pen = Pens.Red '获得红色的默认画笔

默认画笔的宽度为1,如果要获得一个指定宽度的画笔,可以采用下面的语法:

Dim 变量名 As New Pen(颜色, 宽度)

例如:

Dim pn As New Pen(Color.Green, 5) '获得一个绿色的宽度为5的画笔

Pen有一个DashStyle属性,用于定义通过此画笔绘制出的线条类型,该属性是一个DashStyle型枚举,包括以下可选值:

Dash         由线段构成的直线。
DashDot      由线段和点间隔构成的直线。
DashDotDot   由线段和连续两个点间隔构成的直线
Dot          由点构成的直线。
Solid        实线,这是默认值

rect RectangleF类型,用于指定四边形的位置和大小
corners SizeF类型,用于指定四边形的角半径。
x, y, width, height 分别用于直接指定四边形的水平位置、垂直位置、宽度和高度

示例

Dim file As String = "c:\temp\test.pdf"
Dim
pdc As New PDFCreator()
Dim
rect As New RectangleF(72, 72, 100, 50)
pdc.DrawRectangle(pens.Red, rect)
rect.Offset(130, 0)
pdc.DrawRectangle(pens.Red, rect,
New SizeF(5, 5))
pdc.Save(file)
pdc.Show()

生成的文档:

FillRectangle

FillRectangle用于填充四边形,其语法为:

FillRectangle(color, rect)
FillRectangle(brush, rect)
FillRectangle(color, rect, corners)
FillRectangle(brush, rect, corners)
FillRectangle(color, x, y, width, height)
FillRectangle(
brush, x, y, width, height)
 

 

参数 说明
color 填充颜色
brush 指定用于填充的画刷,Brush类型。

过Brushes可以返回各种颜色的默认画刷,例如:

Dim br As Brush = Brushes.Red '获得红色的画刷

可以用自定义的颜色来定义画刷,例如:

Dim br1 As Brush = New SolidBrush(Color.FromARGB(255,255,192,203))
Dim
br2 As Brush = New SolidBrush(Color.FromARGB(-16181))

rect RectangleF类型,用于指定四边形的位置和大小
corners SizeF类型,用于指定矩形的角半径。
x, y, width, height 分别用于直接指定四边形的水平位置、垂直位置、宽度和高度

示例

Dim file As String = "c:\temp\test.pdf"
Dim
pdc As New PDFCreator()
Dim
rect As New RectangleF(100, 100, 250, 150)
pdc.FillRectangle(color.PowderBlue, rect,
New SizeF(10, 10))
pdc.Save(file)

pdc.Show()

生成的文档为:

DrawLine

DrawLine用于绘制直线,其语法为:

DrawLine(pen, x1, y1, x2, y2)

DrawLine(pen, pt1, pt2)
 

参数 说明
pen 画笔
x1 直线起始水平位置
y1 直线起始垂直位置
x2 直线结束水平位置
y2 直线结束垂直位置
pt1 PointF类型,直线起始位置
pt2 PointF类型,直线结束位置

示例

Dim file As String = "c:\temp\test.pdf"
Dim
pdc As New PDFCreator()
Dim
thinPen As New Pen(Color.Black, 1)
Dim
thickPen As New Pen(Color.Blue, 3)
Dim
dotPen As New Pen(Color.Red, 2)
dotPen.DashStyle = DashStyle.Dot
p
dc.DrawLine(thinPen, 100, 100, 300, 100)
pdc.DrawLine(thickPen, 100, 120, 300, 120)
pdc.DrawLine(dotPen, 100, 140, 300, 140)
pdc.DrawLine(pens.Green, 100, 160, 300, 160)
pdc.Save(file)
pdc.Show()

绘制出的线条:


本页地址:http://www.foxtable.com/webhelp/topics/6082.htm