Ver Mensaje Individual
  #5 (permalink)  
Antiguo 08/02/2011, 11:28
matarasky
 
Fecha de Ingreso: julio-2010
Mensajes: 20
Antigüedad: 14 años, 3 meses
Puntos: 0
Exclamación Respuesta: referencia a objeto no establecida com instancia de un objeto,Proyecto Imp

no toma el listview para previzualizarlo
Código:
 Dim vform2 As PrintableListView.PrintableListView
*Private Sub m_btnPageSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_btnPageSetup.Click
* * * * * * vform2 = new PrintableListView.PrintableListView 
* * * * * * vform2.PageSetup()
* * * * End Sub
Código:
 Public Class PrintableListView
        Inherits ListView
        Private Function GetItem(ByVal index As Integer) As ListViewItem
            Return If(Me.m_bPrintSel, MyBase.SelectedItems.Item(index), MyBase.Items.Item(index))
        End Function
        Private Sub OnBeginPrint(ByVal sender As Object, ByVal e As PrintEventArgs)
            Me.PreparePrint
        End Sub
        Private Sub OnPrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
            Dim nNumItems As Integer = Me.GetItemsCount
            If ((nNumItems = 0) OrElse (Me.m_nStartRow >= nNumItems)) Then
                e.HasMorePages = False
            Else
                Dim rectFull As RectangleF
                Dim ch As ColumnHeader
                Dim sf As StringFormat
                Dim rectText As RectangleF
                Dim nNextStartCol As Integer = 0
                Dim x As Single = 0!
                Dim y As Single = 0!
                Dim cx As Single = 4!
                Dim fScale As Single = 1!
                Dim fRowHeight As Single = 0!
                Dim fColWidth As Single = 0!
                Dim bUnprintable As Boolean = False
                Dim g As Graphics = e.Graphics
                If (g.VisibleClipBounds.X < 0!) Then
                    rectFull = e.MarginBounds
                    rectFull = New RectangleF(((rectFull.X / Me.m_fDpi) * 100!), ((rectFull.Y / Me.m_fDpi) * 100!), ((rectFull.Width / Me.m_fDpi) * 100!), ((rectFull.Height / Me.m_fDpi) * 100!))
                Else
                    rectFull = New RectangleF((e.MarginBounds.Left - ((e.PageBounds.Width - g.VisibleClipBounds.Width) / 2!)), (e.MarginBounds.Top - ((e.PageBounds.Height - g.VisibleClipBounds.Height) / 2!)), CSng(e.MarginBounds.Width), CSng(e.MarginBounds.Height))
                End If
                Dim rectBody As RectangleF = RectangleF.Inflate(rectFull, 0!, (-2! * Me.Font.GetHeight(g)))
                Dim sfmt As New StringFormat
                sfmt.Alignment = StringAlignment.Center
                g.DrawString(Me.m_strTitle, Me.Font, Brushes.Black, rectFull, sfmt)
                sfmt.LineAlignment = StringAlignment.Far
                g.DrawString(("Page " & Me.m_nPageNumber), Me.Font, Brushes.Black, rectFull, sfmt)
                If (((Me.m_nStartCol = 0) AndAlso Me.m_bFitToPage) AndAlso (Me.m_fListWidth > rectBody.Width)) Then
                    fScale = (rectBody.Width / Me.m_fListWidth)
                End If
                rectFull = New RectangleF((rectFull.X / fScale), (rectFull.Y / fScale), (rectFull.Width / fScale), (rectFull.Height / fScale))
                rectBody = New RectangleF((rectBody.X / fScale), (rectBody.Y / fScale), (rectBody.Width / fScale), (rectBody.Height / fScale))
                g.ScaleTransform(fScale, fScale)
                g.PageUnit = GraphicsUnit.Inch
                g.PageScale = 0.01!
                nNextStartCol = 0
                y = rectBody.Top
                Dim brushHeader As Brush = New SolidBrush(Color.LightGray)
                Dim fontHeader As New Font(Me.Font, FontStyle.Bold)
                fRowHeight = (fontHeader.GetHeight(g) * 3!)
                x = rectBody.Left
                Dim i As Integer = Me.m_nStartCol
                Do While (i < MyBase.Columns.Count)
                    ch = MyBase.Columns.Item(i)
                    fColWidth = Me.m_arColsWidth(i)
               If ((x + fColWidth) <= rectBody.Right) Then
                        g.FillRectangle(brushHeader, x, y, fColWidth, fRowHeight)
                        g.DrawRectangle(Pens.Black, x, y, fColWidth, fRowHeight)
                        sf = New StringFormat
                 If (ch.TextAlign = HorizontalAlignment.Left) Then
                            sf.Alignment = StringAlignment.Near
               ElseIf (ch.TextAlign = HorizontalAlignment.Center) Then
                            sf.Alignment = StringAlignment.Center
               Else
                            sf.Alignment = StringAlignment.Far
                End If
          sf.LineAlignment = StringAlignment.Center
        sf.FormatFlags = StringFormatFlags.NoWrap
      sf.Trimming = StringTrimming.EllipsisCharacter
    rectText = New RectangleF((x + cx), y, ((fColWidth - 1!) - (2! * cx)), fRowHeight)
                        g.DrawString(ch.Text, fontHeader, Brushes.Black, rectText, sf)
                        x = (x + fColWidth)
                    Else
                        If (i = Me.m_nStartCol) Then
                            bUnprintable = True
                        End If
                        nNextStartCol = i
                        Exit Do
                    End If
                    i += 1
                Loop
                y = (y + fRowHeight)
                Dim nRow As Integer = Me.m_nStartRow
                Dim bEndOfPage As Boolean = False
                Do While (Not bEndOfPage AndAlso (nRow < nNumItems))
                    Dim item As ListViewItem = Me.GetItem(nRow)
                    fRowHeight = (((CSng(item.Bounds.Height) / Me.m_fDpi) * 100!) + 5!)
                    If ((y + fRowHeight) > rectBody.Bottom) Then
                        bEndOfPage = True
                    Else
                        x = rectBody.Left
                        For i = Me.m_nStartCol To MyBase.Columns.Count - 1
                            ch = MyBase.Columns.Item(i)
                            fColWidth = Me.m_arColsWidth(i)
                            If ((x + fColWidth) <= rectBody.Right) Then
                                g.DrawRectangle(Pens.Black, x, y, fColWidth, fRowHeight)
                                sf = New StringFormat
                                If (ch.TextAlign = HorizontalAlignment.Left) Then
                                    sf.Alignment = StringAlignment.Near
                                ElseIf (ch.TextAlign = HorizontalAlignment.Center) Then
                                    sf.Alignment = StringAlignment.Center
                                Else
                                    sf.Alignment = StringAlignment.Far
                                End If
                                sf.LineAlignment = StringAlignment.Center
                                sf.FormatFlags = StringFormatFlags.NoWrap
                                sf.Trimming = StringTrimming.EllipsisCharacter
                                Dim strText As String = If((i = 0), item.Text, item.SubItems.Item(i).Text)
                                Dim font As Font = If((i = 0), item.Font, item.SubItems.Item(i).Font)
                                rectText = New RectangleF((x + cx), y, ((fColWidth - 1!) - (2! * cx)), fRowHeight)
                                g.DrawString(strText, font, Brushes.Black, rectText, sf)
                                x = (x + fColWidth)
                            Else
                                nNextStartCol = i
                                Exit For
                            End If
                        Next i
                        y = (y + fRowHeight)
                        nRow += 1
                    End If
                Loop
                If (nNextStartCol = 0) Then
                    Me.m_nStartRow = nRow
                End If
                Me.m_nStartCol = nNextStartCol
                Me.m_nPageNumber += 1
                e.HasMorePages = (((Not bUnprintable AndAlso (Me.m_nStartRow > 0)) AndAlso (Me.m_nStartRow < nNumItems)) OrElse (Me.m_nStartCol > 0))
                If Not e.HasMorePages Then
                    Me.m_nPageNumber = 1
                    Me.m_nStartRow = 0
                    Me.m_nStartCol = 0
                End If
                brushHeader.Dispose
            End If
        End Sub
        Private Sub PreparePrint()
            Me.m_fListWidth = 0!
            Me.m_arColsWidth = New Single(MyBase.Columns.Count  - 1) {}
            Dim g As Graphics = MyBase.CreateGraphics
            Me.m_fDpi = g.DpiX
            g.Dispose
            Dim i As Integer
            For i = 0 To MyBase.Columns.Count - 1
                Dim ch As ColumnHeader = MyBase.Columns.Item(i)
                Dim fWidth As Single = (((CSng(ch.Width) / Me.m_fDpi) * 100!) + 1!)
                Me.m_fListWidth = (Me.m_fListWidth + fWidth)
                Me.m_arColsWidth(i) = fWidth
            Next i
            Me.m_fListWidth += 1
        End Sub
        Public Sub PrintPreview()
            Me.m_printDoc.DocumentName = "Documentos Asociados al Cómite Paritario"
            Me.m_nPageNumber = 1
            Me.m_bPrintSel = False
            Me.m_previewDlg.ShowDialog(Me)
        End Sub
        ' Properties
        Public Property FitToPage As Boolean
            Get
                Return Me.m_bFitToPage
            End Get
            Set(ByVal value As Boolean)
                Me.m_bFitToPage = value
            End Set
        End Property
        Public m_bPrintSel As Boolean = False
        Public m_previewDlg As PrintPreviewDialog = New PrintPreviewDialog
        Public m_printDlg As PrintDialog = New PrintDialog
        Public m_printDoc As PrintDocument = New PrintDocument
        Public m_setupDlg As PageSetupDialog = New PageSetupDialog
        Public m_strTitle As String = ""
    End Class

Última edición por matarasky; 08/02/2011 a las 12:16