您的批评和鼓励都是我把编程无限办好的动力! 您编程时遇到困难,或遇到不顺心的事想发发牢骚尽管到这里来吧! 虽然本网力求全面,但也不能包罗万象,这些我筛选出的优秀网站连接就是对本站最好的补充! 学习编程当然也离不开书本了,这里收集大量编程书籍! 编程无限之源码超市,这里收集的代码令你意想不到的全面! 欢迎光临编程网校,这里专门收集VB/CB入门文章及技术文章! 欢迎光临编程无限!
     
       
 
当前位置:英文资料 >> ActiveX
Grid Printing Made Easy
  资料类型: ActiveX 上传时间: 2001-02-21 阅读次数: 1189



Sub GridPrint(Grid As Control, szTitle As String, bLines As Integer)

' *** Print a grid control ***



Dim nRow As Long

Dim nCol As Long

Dim sCurrentX As Single

Dim sCurrentY As Single

Dim sMaxLine As Single

Dim nPage As Integer

Dim szPage As String

Dim sOldY As Single

Dim sPageWidth As Single

Dim sBeginLeft As Single

Dim sBeginGrid As Single



If (Grid.Rows = 0) Then Exit Sub



' *** We resize the grid ***

GridSize Grid



' *** We look for the maximum size for the fontsize ***

sMaxLine = 99999999



' *** By default, we set the fontsize of the grid ***

Printer.FontSize = Grid.FontSize



' *** Here is the maximum width of the page

sPageWidth = Printer.Width * 0.94 - 200



' *** We calculate the maximum possible fontsize ***

Do While (sMaxLine > sPageWidth) And (Printer.FontSize > 0)

sMaxLine = 0

For nCol = 0 To Grid.Cols - 1

sMaxLine = sMaxLine + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol)

Next



' *** We change the fontsiz if needed ***

If (sMaxLine > sPageWidth) Then Printer.FontSize = Printer.FontSize - 1

Loop



' *** We begin on page 1 ***

nPage = 1



' *** We put The title ***

' *** and the headers of each column ***

GoSub PRINT_HEADERS



For nRow = 1 To Grid.Rows - 1

If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)



' *** We print on a new page if needed ***

If (sCurrentY >= Printer.Height * 0.93 - Printer.TextHeight("A")) Then

If (bLines = True) Then

' *** Bottom line

Printer.Line (sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)

' *** Left line ***

Printer.Line (sBeginLeft, sBeginGrid)-(sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)

' *** Right line ***

Printer.Line (sMaxLine, sBeginGrid)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)

End If



Printer.NewPage

nPage = nPage + 1



' *** We put The title ***

' *** and the headers of each column ***

GoSub PRINT_HEADERS



End If



sCurrentX = 4 * Printer.TwipsPerPixelX



For nCol = 0 To Grid.Cols - 1

If (nCol > 0) Then

sCurrentX = sCurrentX + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol - 1)



If bLines = True Then Printer.Line (sCurrentX - 4 * Printer.TwipsPerPixelX, sBeginGrid)-(sCurrentX - 4 * Printer.TwipsPerPixelX, Printer.CurrentY + (Printer.TextHeight("A") / 2) - 4 * Printer.TwipsPerPixelY)

End If



' *** Print cell text ***

Grid.Col = nCol

Grid.Row = nRow

Printer.CurrentX = sCurrentX

Printer.CurrentY = sCurrentY + (Printer.TextHeight("A") / 2)

Printer.Print Grid.Text

Next



sCurrentY = sCurrentY + (Printer.TextHeight("A") * 2)

Next

If (bLines = True) Then

' *** Bottom line

Printer.Line (sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)

' *** Left line ***

Printer.Line (sBeginLeft, sBeginGrid)-(sBeginLeft, sCurrentY - 4 * Printer.TwipsPerPixelY)

' *** Right line ***

Printer.Line (sMaxLine, sBeginGrid)-(sMaxLine, sCurrentY - 4 * Printer.TwipsPerPixelY)

End If



Printer.EndDoc



Exit Sub



PRINT_HEADERS:

' *** We print the title ***

sCurrentY = Printer.CurrentY

Printer.FontBold = True

Printer.Print szTitle

Printer.FontBold = False

Printer.Print ""



' *** We print the page number on the first line ***

sOldY = Printer.CurrentY

szPage = "Page " & CStr(nPage)

Printer.FontItalic = True

Printer.CurrentX = sPageWidth - Printer.TextWidth(szPage)

Printer.CurrentY = sCurrentY

Printer.Print szPage

Printer.FontItalic = False

Printer.CurrentY = sOldY



' *** We print the grid ***

Printer.CurrentY = Printer.CurrentY + (Printer.TextHeight("A"))

sCurrentY = Printer.CurrentY

sBeginGrid = sCurrentY

sBeginLeft = 0

sCurrentX = 4 * Printer.TwipsPerPixelX



' *** We print the header of each column ***

If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)



Printer.Print

sCurrentY = Printer.CurrentY + (Printer.TextHeight("A") / 2)

For nCol = 0 To Grid.Cols - 1

If (nCol > 0) Then sCurrentX = sCurrentX + (Printer.FontSize / Grid.FontSize) * Grid.ColWidth(nCol - 1)



' *** Print cell text ***

Grid.Col = nCol

Grid.Row = 0

Printer.CurrentX = sCurrentX

Printer.CurrentY = sCurrentY

Printer.Print Grid.Text

Next



sCurrentY = sCurrentY + (Printer.TextHeight("A") * 1.5)

Printer.Print



If (bLines = True) Then Printer.Line (sBeginLeft, sCurrentY)-(sMaxLine, sCurrentY)



Return



End Sub

Sub GridSize(grdGrid As Control)

' *** We resize the grid ***



Dim szTmp As String

Dim nColSize As Long

Dim nCounter As Long

Dim nArray() As Integer

Dim nRow As Integer



ReDim nArray(grdGrid.Cols)

For nCounter = 0 To grdGrid.Cols - 1

For nRow = 0 To grdGrid.Rows - 1

szTmp = GridGetText(grdGrid, nRow, nCounter)

nColSize = IIf(Len(szTmp) < 1, 1, Len(szTmp))

If (nArray(nCounter) < nColSize) Then nArray(nCounter) = nColSize

Next

Next



For nCounter = 0 To grdGrid.Cols - 1

grdGrid.ColWidth(nCounter) = nArray(nCounter) * grdGrid.FontSize * 14

Next



End Sub

Function GridGetText(grdGrid As Control, ByVal nRow As Long, ByVal nCol As Long) As String

' *** We get the text of a cell in the grid ***



Dim nOldCol As Long



nOldCol = grdGrid.Col



grdGrid.Row = nRow

grdGrid.Col = nCol

GridGetText = grdGrid.Text



grdGrid.Col = nOldCol



End Function


推荐给朋友 点 评( 0 ) 返回前页 关闭此页
   
  本类最热文章排名:
  1.Pop-Up Menu
2.Remove Selected Item...
3.Simulate Hover Butto...
4.Hide Taskbar
5.Make a Combo Drop Do...
6.Mouse Button Up Or Down Status
7.Selecting An Item From The DBCombo
8.Dragging A Form Or Control
9.Copying Data From A Grid Control
10.Placing The Cursor O...
   
   
  评论:
 
 
 

 

关于本站 版权声明 联系方法
编程无限 V4.1 Copyright © 1999-2008 21code.com

京ICP备05006938号