自己看看源码吧。
关键看你要预览的是什么东西,大体上的结构是用一个Picturebox,不管是图片还是文字,扔进去就行了。

解决方案 »

  1.   

    用picture做容器。把你的打印函数中的Printer全部换成Picture就是预览的函数了。不过最好的办法还是用一个函数同时来实现打印和预览。
      

  2.   

    下面是我帮你写的测试代码。
    新建一个文本文档,将下面的内容贴入,再将后缀名改为frm,用VB打开就行了。
    VERSION 5.00
    Begin VB.Form Form1 
       BorderStyle     =   1  'Fixed Single
       Caption         =   "Form1"
       ClientHeight    =   5460
       ClientLeft      =   45
       ClientTop       =   330
       ClientWidth     =   7965
       LinkTopic       =   "Form1"
       MaxButton       =   0   'False
       ScaleHeight     =   5460
       ScaleWidth      =   7965
       StartUpPosition =   3  '窗口缺省
       Begin VB.CommandButton Command2 
          Caption         =   "PrintView"
          Height          =   435
          Left            =   6480
          TabIndex        =   2
          Top             =   4860
          Width           =   1335
       End
       Begin VB.CommandButton Command1 
          Caption         =   "Print"
          Height          =   435
          Left            =   120
          TabIndex        =   1
          Top             =   4920
          Width           =   1335
       End
       Begin VB.PictureBox Picture1 
          BackColor       =   &H80000009&
          Height          =   4635
          Left            =   120
          ScaleHeight     =   4575
          ScaleWidth      =   7575
          TabIndex        =   0
          Top             =   60
          Width           =   7635
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option ExplicitPrivate Sub Command1_Click()
    Printer.Orientation = 2
    PrintExemple Printer.Width, Printer.Height, Printer   '打印
    Printer.EndDoc
    End SubPrivate Sub Command2_Click()
    Picture1.Cls
    PrintExemple Picture1.Width, Picture1.Height, Picture1    '预览
    End SubPrivate Sub Form_Load()
    Picture1.AutoRedraw = True
    End Sub'打印函数
    Private Sub PrintExemple(MaxWidth As Single, MaxHeight As Single, Mo As Object)
    Dim pLeft As Single, pTop As Single, pWidth As Single, pHeight As Single  '表示实际打印范围的变量
    pLeft = MaxWidth / 30
    pTop = MaxHeight / 30
    pWidth = MaxWidth - pLeft * 2
    pHeight = MaxHeight - pTop * 2Mo.Line (pLeft, pTop)-(pLeft + pWidth, pTop + pHeight), , B    '画一个矩形
    Mo.Circle (pLeft + pWidth / 2, pTop + pHeight / 2), pHeight / 2 '画一个圆'在中间打一行字
    With Mo
    .FontName = "宋体"
    .FontSize = GetFontSize(12, Mo)
    .FontBold = True
    .CurrentX = pLeft + (pWidth - .TextWidth("打印测试程序")) / 2
    .CurrentY = pTop + (pHeight - .TextHeight("打印测试程序")) / 2
    End WithMo.Print "打印测试程序"
    End Sub
    '根据不同的情况调整字体的函数
    Private Function GetFontSize(oSize As Integer, Mo As Object) As Integer
    Dim i As Long, n As Integer
    Dim FB As Boolean, pSize As Integer, pFontName As StringIf Mo Is Printer Then
    GetFontSize = oSize
    Else
    '打印机原来的字体设置
    pSize = Printer.FontSize
    FB = Printer.FontBold
    pFontName = Printer.FontName'设置打印机的字体
    Printer.FontName = Mo.FontName
    Printer.FontBold = Mo.FontBold
    Printer.FontSize = oSize   If Printer.Orientation = 1 Then
          Do
          i = i + 1
          Loop Until Printer.TextWidth(Space(i)) > Printer.Width
       Else
          Do
          i = i + 1
          Loop Until Printer.TextWidth(Space(i)) > Printer.Height
       End If
       
       Do
       n = n + 1
       Mo.FontSize = n
       Loop Until Mo.TextWidth(Space(i)) > Mo.Width
      
    '还原打印机的字体设置
    Printer.FontName = pFontName
    Printer.FontSize = pSize
    Printer.FontBold = FBGetFontSize = n
    End If
    End Function
      

  3.   

    我想把PICTUREBOX里的内容不仅仅是图片啊还有文字! 预览到另一个页面!
      

  4.   

    不是的啊!
    是有两个窗体啊!而且都有PICTUREBOX!一个是原始窗体,另个是用来做预览的啊!也就是用来做预览PICTUREBOX里面是那个原始窗体里面的PICTUREBOX里面的内容