CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  控件

如何将picture控件中的内容输出到打印机?

楼主no_com(探花)2002-05-06 15:38:29 在 VB / 控件 提问

如何将picture控件中的内容输出到打印机?  
   
  如果picture控件作为容器呢?比如说在picture控件中还有label怎么办?  
  +++++++++++++  
  打印问题 问题点数:100、回复次数:12Top

1 楼no_com(探花)回复于 2002-05-06 16:41:24 得分 0

upTop

2 楼COOL099(Alan Zjou)回复于 2002-05-06 18:07:10 得分 0

將PictureBox區域的屏幕拷貝下來,送到打印機就行了.Top

3 楼no_com(探花)回复于 2002-05-06 18:48:22 得分 0

如果picture控件作为容器呢?比如说在picture控件中还有label怎么办?Top

4 楼ferrytang(欢迎你)回复于 2002-05-06 18:51:03 得分 0

请关注下面的贴子  
  http://www.csdn.net/expert/topic/701/701403.xml?temp=.7961542  
  Top

5 楼Zhang_1978(小卿)回复于 2002-05-06 19:37:13 得分 40

Private   Sub   PRINT_Click()  
  Dim   intI   As   Long  
  For   intI   =   0   To   Me.Controls.Count   -   1  
        If   TypeName(Me.Controls(intI))   =   "TextBox"   Then  
                Me.Controls(intI).Appearance   =   0  
                Me.Controls(intI).BorderStyle   =   0  
        End   If  
  Next   intI  
  On   Error   GoTo   KKK  
          Dim   sx   As   Long,   sy   As   Long,   hDC   As   Long  
          Dim   px   As   Long,   py   As   Long,   I   As   Integer  
           
          Me.ScaleMode   =   vbPixels  
           
          sx   =   Me.Width   /   Screen.TwipsPerPixelX  
          sy   =   Me.Height   /   Screen.TwipsPerPixelY  
          PicPrint.Width   =   sx  
          PicPrint.Height   =   sy  
          For   I   =   0   To   Controls.Count   -   1  
                  If   TypeName(Controls(I))   =   "Menu"   Then   Controls(I).Visible   =   False  
                  If   Controls(I).Name   =   "PicPrint"   Then   Controls(I).Visible   =   False  
                  If   TypeName(Controls(I))   =   "TextBox"   Then   Controls(I).BorderStyle   =   0  
          Next  
          DoEvents  
   
          Text1.SetFocus  
          PicPrint.AutoRedraw   =   True  
           
          hDC   =   GetWindowDC(Me.hwnd)  
          BitBlt   PicPrint.hDC,   -4,   -4,   sx,   sy,   hDC,   0,   0,   vbSrcCopy  
          ReleaseDC   Me.hwnd,   hDC  
          PicPrint.AutoRedraw   =   False  
           
          For   I   =   0   To   Controls.Count   -   1  
                  If   TypeName(Controls(I))   =   "Menu"   Then   Controls(I).Visible   =   True  
          Next  
   
           
          Set   PicPrint.Picture   =   PicPrint.Image  
           
          Dim   w   As   Long,   h   As   Long  
          Printer.Orientation   =   vbPRORLandscape  
          Me.ScaleMode   =   vbTwips  
          Printer.ScaleMode   =   vbTwips  
          w   =   PicPrint.Width   *   n   \   100  
          h   =   PicPrint.Height   *   n   \   100  
          px   =   (Printer.ScaleWidth   -   w)   /   2  
          py   =   (Printer.ScaleHeight   -   h)   /   2  
          Printer.PaintPicture   PicPrint.Picture,   px,   py,   w,   h  
          Printer.EndDoc  
          For   intI   =   0   To   Me.Controls.Count   -   1  
        If   TypeName(Me.Controls(intI))   =   "TextBox"   Then  
                Me.Controls(intI).Appearance   =   0  
                Me.Controls(intI).BorderStyle   =   1  
        End   If  
  Next   intI  
      Exit   Sub  
  KKK:  
  MsgBox   "打印机连接错误!",   vbOKOnly,   warning  
   
  End   Sub  
  Top

6 楼505(五五)回复于 2002-05-06 20:13:17 得分 30

如何将picture控件中的内容输出到打印机?  
   
  如果picture控件作为容器呢?比如说在picture控件中还有label怎么办?  
  =============================================================  
   
  可直接打印,pictureBox中的控件与pictureBox中的内容无关  
          Printer.PaintPicture   Picture1,   0,   0,   w,   h  
          Printer.EndDoc  
  Top

7 楼dirotac(一粒沙尘)回复于 2002-05-06 20:46:16 得分 30

Private   Type   PALETTEENTRY  
        peRed   As   Byte  
        peGreen   As   Byte  
        peBlue   As   Byte  
        peFlags   As   Byte  
  End   Type  
   
  Private   Type   LOGPALETTE  
        palVersion   As   Integer  
        palNumEntries   As   Integer  
        palPalEntry(255)   As   PALETTEENTRY     '   Enough   for   256   colors.  
  End   Type  
   
  Private   Type   GUID  
        Data1   As   Long  
        Data2   As   Integer  
        Data3   As   Integer  
        Data4(7)   As   Byte  
  End   Type  
   
  Private   Const   RASTERCAPS   As   Long   =   38  
  Private   Const   RC_PALETTE   As   Long   =   &H100  
  Private   Const   SIZEPALETTE   As   Long   =   104  
   
  Private   Type   RECT  
        Left   As   Long  
        Top   As   Long  
        Right   As   Long  
        Bottom   As   Long  
  End   Type  
   
  Private   Declare   Function   CreateCompatibleDC   Lib   "GDI32"   (ByVal   hDC   As   Long)   As   Long  
  Private   Declare   Function   CreateCompatibleBitmap   Lib   "GDI32"   (ByVal   hDC   As   Long,   ByVal   nWidth   As   Long,   ByVal   nHeight   As   Long)   As   Long  
  Private   Declare   Function   GetDeviceCaps   Lib   "GDI32"   (ByVal   hDC   As   Long,   ByVal   iCapabilitiy   As   Long)   As   Long  
  Private   Declare   Function   GetSystemPaletteEntries   Lib   "GDI32"   (ByVal   hDC   As   Long,   ByVal   wStartIndex   As   Long,   ByVal   wNumEntries   As   Long,   lpPaletteEntries   As   PALETTEENTRY)   As   Long  
  Private   Declare   Function   CreatePalette   Lib   "GDI32"   (lpLogPalette   As   LOGPALETTE)   As   Long  
  Private   Declare   Function   SelectObject   Lib   "GDI32"   (ByVal   hDC   As   Long,   ByVal   hObject   As   Long)   As   Long  
  Private   Declare   Function   BitBlt   Lib   "GDI32"   (ByVal   hDCDest   As   Long,   ByVal   XDest   As   Long,   ByVal   YDest   As   Long,   ByVal   nWidth   As   Long,   ByVal   nHeight   As   Long,   ByVal   hDCSrc   As   Long,   ByVal   XSrc   As   Long,   ByVal   YSrc   As   Long,   ByVal   dwRop   As   Long)   As   Long  
  Private   Declare   Function   DeleteDC   Lib   "GDI32"   (ByVal   hDC   As   Long)   As   Long  
  Private   Declare   Function   GetForegroundWindow   Lib   "USER32"   ()   As   Long  
  Private   Declare   Function   SelectPalette   Lib   "GDI32"   (ByVal   hDC   As   Long,   ByVal   hPalette   As   Long,   ByVal   bForceBackground   As   Long)   As   Long  
  Private   Declare   Function   RealizePalette   Lib   "GDI32"   (ByVal   hDC   As   Long)   As   Long  
  Private   Declare   Function   GetWindowDC   Lib   "USER32"   (ByVal   hWnd   As   Long)   As   Long  
  Private   Declare   Function   GetDC   Lib   "USER32"   (ByVal   hWnd   As   Long)   As   Long  
  Private   Declare   Function   GetWindowRect   Lib   "USER32"   (ByVal   hWnd   As   Long,   lpRect   As   RECT)   As   Long  
  Private   Declare   Function   ReleaseDC   Lib   "USER32"   (ByVal   hWnd   As   Long,   ByVal   hDC   As   Long)   As   Long  
  Private   Declare   Function   GetDesktopWindow   Lib   "USER32"   ()   As   Long  
   
  Private   Type   PicBmp  
        Size   As   Long  
        Type   As   Long  
        hBmp   As   Long  
        hPal   As   Long  
        Reserved   As   Long  
  End   Type  
   
  Private   Declare   Function   OleCreatePictureIndirect   Lib   "olepro32.dll"   (PicDesc   As   PicBmp,   RefIID   As   GUID,   ByVal   fPictureOwnsHandle   As   Long,   IPic   As   IPicture)   As   Long  
  Top

8 楼dirotac(一粒沙尘)回复于 2002-05-06 20:46:40 得分 0

Private   Sub   print_Click()  
   
          PrintPictureToFitPage   Printer,   CaptureWindow(Me.Picture1.hWnd,   False,   0,   0,   Screen.Width   \   Screen.TwipsPerPixelX,   Screen.Height   \   Screen.TwipsPerPixelY)  
          Printer.EndDoc  
  End   Sub  
  Public   Sub   PrintPictureToFitPage(Prn   As   Printer,   Pic   As   Picture)  
   
          Const   vbHiMetric   As   Integer   =   8  
          Dim   PicRatio   As   Double  
          Dim   PrnWidth   As   Double  
          Dim   PrnHeight   As   Double  
          Dim   PrnRatio   As   Double  
          Dim   PrnPicWidth   As   Double  
          Dim   PrnPicHeight   As   Double  
   
          '   Determine   if   picture   should   be   printed   in   landscape   or   portrait  
          '   and   set   the   orientation.  
          If   Pic.Height   >=   Pic.Width   Then  
                  Prn.Orientation   =   vbPRORPortrait       '   Taller   than   wide.  
          Else  
                  Prn.Orientation   =   vbPRORLandscape     '   Wider   than   tall.  
          End   If  
   
          '   Calculate   device   independent   Width-to-Height   ratio   for   picture.  
          If   Pic.Width   =   0   And   Pic.Height   =   0   Then  
   
        MsgBox   "没有图可打啊!"  
          Exit   Sub  
   
        End   If  
   
          PicRatio   =   Pic.Width   /   Pic.Height  
   
          '   Calculate   the   dimentions   of   the   printable   area   in   HiMetric.  
          PrnWidth   =   Prn.ScaleX(Prn.ScaleWidth,   Prn.ScaleMode,   vbHiMetric)  
          PrnHeight   =   Prn.ScaleY(Prn.ScaleHeight,   Prn.ScaleMode,   vbHiMetric)  
          '   Calculate   device   independent   Width   to   Height   ratio   for   printer.  
          PrnRatio   =   PrnWidth   /   PrnHeight  
   
          '   Scale   the   output   to   the   printable   area.  
          If   PicRatio   >=   PrnRatio   Then  
                  '   Scale   picture   to   fit   full   width   of   printable   area.  
                  PrnPicWidth   =   Prn.ScaleX(PrnWidth,   vbHiMetric,   Prn.ScaleMode)  
                  PrnPicHeight   =   Prn.ScaleY(PrnWidth   /   PicRatio,   vbHiMetric,   Prn.ScaleMode)  
          Else  
                  '   Scale   picture   to   fit   full   height   of   printable   area.  
                  PrnPicHeight   =   Prn.ScaleY(PrnHeight,   vbHiMetric,   Prn.ScaleMode)  
                  PrnPicWidth   =   Prn.ScaleX(PrnHeight   *   PicRatio,   vbHiMetric,   Prn.ScaleMode)  
          End   If  
   
          '   Print   the   picture   using   the   PaintPicture   method.  
          Prn.PaintPicture   Pic,   0,   0,   PrnPicWidth,   PrnPicHeight  
  End   Sub  
      Public   Function   CaptureWindow(ByVal   hWndSrc   As   Long,   ByVal   Client   As   Boolean,   ByVal   LeftSrc   As   Long,   ByVal   TopSrc   As   Long,   ByVal   WidthSrc   As   Long,   ByVal   HeightSrc   As   Long)   As   Picture  
   
      Dim   hDCMemory   As   Long  
      Dim   hBmp   As   Long  
      Dim   hBmpPrev   As   Long  
      Dim   r   As   Long  
      Dim   hDCSrc   As   Long  
      Dim   hPal   As   Long  
      Dim   hPalPrev   As   Long  
      Dim   RasterCapsScrn   As   Long  
      Dim   HasPaletteScrn   As   Long  
      Dim   PaletteSizeScrn   As   Long  
      Dim   LogPal   As   LOGPALETTE  
   
        '   Depending   on   the   value   of   Client   get   the   proper   device   context.  
        If   Client   Then  
              hDCSrc   =   GetDC(hWndSrc)   '   Get   device   context   for   client   area.  
        Else  
              hDCSrc   =   GetWindowDC(hWndSrc)   '   Get   device   context   for   entire  
                                                                          '   window.  
        End   If  
   
        '   Create   a   memory   device   context   for   the   copy   process.  
        hDCMemory   =   CreateCompatibleDC(hDCSrc)  
        '   Create   a   bitmap   and   place   it   in   the   memory   DC.  
        hBmp   =   CreateCompatibleBitmap(hDCSrc,   WidthSrc,   HeightSrc)  
        hBmpPrev   =   SelectObject(hDCMemory,   hBmp)  
   
        '   Get   screen   properties.  
        RasterCapsScrn   =   GetDeviceCaps(hDCSrc,   RASTERCAPS)   '   Raster  
                                                                                                              '   capabilities.  
        HasPaletteScrn   =   RasterCapsScrn   And   RC_PALETTE               '   Palette  
                                                                                                                  '   support.  
        PaletteSizeScrn   =   GetDeviceCaps(hDCSrc,   SIZEPALETTE)   '   Size   of  
                                                                                                                  '   palette.  
   
        '   If   the   screen   has   a   palette   make   a   copy   and   realize   it.  
        If   HasPaletteScrn   And   (PaletteSizeScrn   =   256)   Then  
              '   Create   a   copy   of   the   system   palette.  
              LogPal.palVersion   =   &H300  
              LogPal.palNumEntries   =   256  
              r   =   GetSystemPaletteEntries(hDCSrc,   0,   256,   LogPal.palPalEntry(0))  
              hPal   =   CreatePalette(LogPal)  
              '   Select   the   new   palette   into   the   memory   DC   and   realize   it.  
              hPalPrev   =   SelectPalette(hDCMemory,   hPal,   0)  
              r   =   RealizePalette(hDCMemory)  
        End   If  
   
        '   Copy   the   on-screen   image   into   the   memory   DC.  
        r   =   BitBlt(hDCMemory,   0,   0,   WidthSrc,   HeightSrc,   hDCSrc,   LeftSrc,   TopSrc,   vbSrcCopy)  
   
  '   Remove   the   new   copy   of   the     on-screen   image.  
        hBmp   =   SelectObject(hDCMemory,   hBmpPrev)  
   
        '   If   the   screen   has   a   palette   get   back   the   palette   that   was  
        '   selected   in   previously.  
        If   HasPaletteScrn   And   (PaletteSizeScrn   =   256)   Then  
              hPal   =   SelectPalette(hDCMemory,   hPalPrev,   0)  
        End   If  
   
        '   Release   the   device   context   resources   back   to   the   system.  
        r   =   DeleteDC(hDCMemory)  
        r   =   ReleaseDC(hWndSrc,   hDCSrc)  
   
        '   Call   CreateBitmapPicture   to   create   a   picture   object   from   the  
        '   bitmap   and   palette   handles.   Then   return   the   resulting   picture  
        '   object.  
        Set   CaptureWindow   =   CreateBitmapPicture(hBmp,   hPal)  
  End   Function  
  Public   Function   CreateBitmapPicture(ByVal   hBmp   As   Long,   ByVal   hPal   As   Long)   As   Picture  
      Dim   r   As   Long  
   
        Dim   Pic   As   PicBmp  
        '   IPicture   requires   a   reference   to   "Standard   OLE   Types."  
        Dim   IPic   As   IPicture  
        Dim   IID_IDispatch   As   GUID  
   
        '   Fill   in   with   IDispatch   Interface   ID.  
        With   IID_IDispatch  
              .Data1   =   &H20400  
              .Data4(0)   =   &HC0  
              .Data4(7)   =   &H46  
        End   With  
   
        '   Fill   Pic   with   necessary   parts.  
        With   Pic  
              .Size   =   Len(Pic)                     '   Length   of   structure.  
              .Type   =   vbPicTypeBitmap       '   Type   of   Picture   (bitmap).  
              .hBmp   =   hBmp                             '   Handle   to   bitmap.  
              .hPal   =   hPal                             '   Handle   to   palette   (may   be   null).  
        End   With  
   
        '   Create   Picture   object.  
        r   =   OleCreatePictureIndirect(Pic,   IID_IDispatch,   1,   IPic)  
   
        '   Return   the   new   Picture   object.  
        Set   CreateBitmapPicture   =   IPic  
  End   Function  
  Top

9 楼IsMe(海底捞针)回复于 2002-05-06 23:50:10 得分 0

sub   PrintPic(pic   as   picturebox)  
    dim   frm   as   form  
    dim   ctl   as   control  
    dim   x   as   single,y   as   single  
    dim   aV()as   boolean  
    dim   I   as   integer  
    dim   col   as   collection  
   
    set   col=new   collection  
    set   frm=pic.parent  
    redim   aV(frm.controls.count-1)  
    for   each   ctl   in   frm.controls  
          if   not   (ctl   is   pic)   then  
            if   not   (ctl.container   is   pic)   then  
                if   ctl.visible   then  
                    col.add   ctl  
                    ctl.visible=false  
                endif  
            endif  
          endif  
    next  
    x=pic.left  
    y=pic.top  
    pic.move   0,0  
    frm.printform  
    for   each   ctl   in   col  
        ctl.visible=true  
    next  
    pic.left=x  
    pic.top=y    
    end   subTop

10 楼no_com(探花)回复于 2002-05-07 20:41:07 得分 0

关注中,那么怎么样知道picture容器里都放了什么控件呢?比如里面有label、text控件等?Top

11 楼no_com(探花)回复于 2002-05-09 19:08:41 得分 0

upTop

12 楼no_com(探花)回复于 2002-05-13 15:16:10 得分 0

关注中,那么怎么样知道picture容器里都放了什么控件呢?比如里面有label、text控件等?  
  Top

相关问题

  • 怎样把自己编写的控件通过打印机输出来
  • 急,高分求:如何将条形码不通过报表控件直接输出到打印机打印
  • 如何将print的输出输出到打印机?
  • 哪里有支持斑马打印机控件下载?
  • 如何将mschart图表输出到打印机。
  • DataGird中的内容能够输出到打印机吗?
  • 如何用 turbo C 控制打印机 输出?
  • VFP如何直接向打印机输出文本?
  • 如何保证打印机输出固定长度的线条
  • 请问如何在打印机上输出旋转的文字?

关键词

  • 控件
  • 内容
  • me
  • 打印
  • picprint
  • picture
  • typeprivate
  • inti
  • 容器
  • sx

得分解答快速导航

  • 帖主:no_com
  • Zhang_1978
  • 505
  • dirotac

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo