首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

求vsprinter的用法解决方法

2012-01-07 
求vsprinter的用法今天要求做一个打印,需要用到vsprinter控件,可是网上没有一点可以使用的信息,希望朋友帮

求vsprinter的用法
今天要求做一个打印,需要用到vsprinter控件,可是网上没有一点可以使用的信息,
希望朋友帮我找个初级使用帮助或者怎么样的例子让我有个认识,现在一点头绪都没有,
谢谢

[解决办法]
Option Explicit

Dim g_Sizing%
Const TOL = 100

Private Sub Form_Load()
vp.ShowGuides = gdShow
CreateDoc
End Sub

Private Sub vp_BeforeUserScroll(Cancel As Boolean)

' prevent scrolling while dragging margins
If g_Sizing Then Cancel = True

End Sub

Private Sub VP_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With vp

' already resizing? show resizing line using client coordinates
If Button = 1 Then
Select Case g_Sizing
Case 1, 2
ctlLine.X1 = X
ctlLine.X2 = X
ctlLine.Y1 = 0
ctlLine.Y2 = 32000
ctlLine.Visible = True
Case 3, 4
ctlLine.X1 = 0
ctlLine.X2 = 32000
ctlLine.Y1 = Y
ctlLine.Y2 = Y
ctlLine.Visible = True
Case Else
ctlLine.Visible = False
End Select
Exit Sub
End If

' convert client to page coordinates
.ClientToPage X, Y

' offer resizing
If Abs(X - .MarginLeft) < TOL Then
g_Sizing = 1
.MousePointer = mpSizeEW
ElseIf Abs(X - (.PageWidth - .MarginRight)) < TOL Then
g_Sizing = 2
.MousePointer = mpSizeEW
ElseIf Abs(Y - .MarginTop) < TOL Then
g_Sizing = 3
.MousePointer = mpSizeNS
ElseIf Abs(Y - (.PageHeight - .MarginBottom)) < TOL Then
g_Sizing = 4
.MousePointer = mpSizeNS
Else
g_Sizing = 0
.MousePointer = mpDefault
End If
End With
End Sub

Private Sub vp_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

' left button only
If Button <> 1 Then Exit Sub

' adjust margins
With vp

.ClientToPage X, Y
Select Case g_Sizing
Case 1
If X > 0 And X < .PageWidth - .MarginRight - 300 Then
.MarginLeft = X
CreateDoc
End If
Case 2
If X < .PageWidth And X > .MarginLeft + 300 Then
.MarginRight = .PageWidth - X
CreateDoc
End If
Case 3
If Y > 0 And Y < .PageHeight - .MarginBottom - 300 Then
.MarginTop = Y
CreateDoc
End If
Case 4
If Y < .PageHeight And Y > .MarginTop + 300 Then
.MarginBottom = .PageHeight - Y
CreateDoc
End If
End Select

' reset all
ctlLine.Visible = False
g_Sizing = 0
.MousePointer = mpDefault
End With
End Sub

Sub CreateDoc()
With vp
.StartDoc
.SpaceAfter = 200
.TextAlign = taJustTop
.FontSize = 18


.Paragraph = "Hello, World. "
.FontSize = 12
.Paragraph = "This is a VSPrinter document. You can set " & _
"the margins by dragging them with the mouse. "
.Paragraph = "Right now the margins are set as follows: "

.SpaceAfter = 0
.AddTable "3000|1000 ", "Property|Value ", _
"MarginLeft| " & Int(.MarginLeft) & "; " & _
"MarginTop| " & Int(.MarginTop) & "; " & _
"MarginRight| " & Int(.MarginRight) & "; " & _
"MarginBottom| " & Int(.MarginBottom) & "; ", RGB(200, 200, 200)
.Paragraph = " "

.SpaceAfter = 200
Dim i%, s$
s = "Some extra content just to fill up a couple of pages. "
For i = 1 To 20
.Paragraph = s & s & s & s & " ( " & i & "). "
Next

.EndDoc
End With
End Sub

Private Sub Command1_Click()
Dim s$
On Error Resume Next
Open App.Path & "\readme.txt " For Binary As #1
s = Input(LOF(1), 1)
Close #1
If Err > 0 Or Len(s) = 0 Then s = "Sorry, can 't find Readme.txt. "
MsgBox s, vbInformation, "Readme.txt "
On Error GoTo 0
End Sub

Private Sub Form_Resize()
On Error Resume Next
vp.Move vp.Left, vp.Top, ScaleWidth - vp.Left * 2, ScaleHeight - vp.Left - vp.Top
End Sub



[解决办法]
readme.txt
MARGINS
------------------------
Allow users to adjust margins using the mouse.

The sample handles the MouseMove and MouseUp events, converting
mouse coordinates into page coordinates. If the user moves the mouse
close to the guides, the mouse pointer changes to show that he can
start dragging the margin.

When the user releases the mouse button, the margin is adjusted and
the document is regenerated to show the changes.

The BeforeUserScroll event is used to prevent scrolling the document
with the mouse while the margins are being dragged.

The main methods, events, and properties used in this sample are:
ClientToPage, BeforeUserScroll, MousePointer,
MarginLeft, MarginTop, MarginRight, MarginBottom.

[解决办法]
那你得画线了,做表头,有点烦

热点排行