Results 1 to 29 of 29

Thread: VB2010 windows forms printing question

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    VB2010 windows forms printing question

    I have designed a fairly lengthy inquiry form that also has a datagridview of meeting dates, reasons. The customer want to be able to print out the current record with complete meeting data.

    The printform control only prints what is visible on the screen, not the entire form or the entire contents of the datagridview of meetings.

    I am at a stand still right now and not sure where to go.

    Can someone please steer me in the right direction?

    Thank you,

    Steve Hathaway

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: VB2010 windows forms printing question

    Here's a little something to get you started - taken strait from a production app:
    Code:
            Private Sub PrintDataViewGrid(ByRef dgv As Windows.Forms.DataGridView, ByVal PrintArgs As Drawing.Printing.PrintPageEventArgs)
    
                Dim linesPerPage As Single = 0
                Dim yPos As Single = 0
                Dim iThisPageLineCount As Integer = 0
                Dim iPos, iTotalColWidth, iColHeaderChars, iAvgColHeaderChars As Integer
                Dim leftMargin As Single = PrintArgs.MarginBounds.Left
                Dim topMargin As Single = PrintArgs.MarginBounds.Top
                Dim itmPrint As Windows.Forms.DataGridViewRow
                Dim line As String = Nothing
                Dim sngColumnPositions() As Single
                Dim sfPlain As Drawing.StringFormat, sfCenter As Drawing.StringFormat
                Dim rectLayout As Drawing.RectangleF
                Dim FontBold As Drawing.Font
                Dim Font As Drawing.Font
    
                'create any string formats and special fonts
                Font = dgv.Font
                sfPlain = New Drawing.StringFormat
                FontBold = New Drawing.Font(Font, Drawing.FontStyle.Bold)
    
                'calculate the number of lines per page.
                linesPerPage = PrintArgs.MarginBounds.Height / Font.GetHeight(PrintArgs.Graphics)
                'PrintDoc.DefaultPageSettings.Bounds.Height
    
                For Each c As Windows.Forms.DataGridViewColumn In dgv.Columns
                    If c.Visible Then
                        iTotalColWidth += c.Width
                        iColHeaderChars += c.HeaderText.Length
                    End If
                Next
    
                iAvgColHeaderChars = Int(iColHeaderChars / dgv.Columns.Count)
    
                'determine our column positions
                iPos = leftMargin
                ReDim sngColumnPositions(dgv.Columns.Count - 1)
                For Each c As Windows.Forms.DataGridViewColumn In dgv.Columns
                    If c.Visible Then
                        sngColumnPositions(c.Index) = iPos
                        iPos += PrintArgs.MarginBounds.Width * (c.Width / iTotalColWidth)
                    Else
                        sngColumnPositions(c.Index) = iPos
                    End If
                Next
    
    
                'add the page header, if any
                If Me.m_PageTitle.Length > 0 Then
                    sfCenter = New Drawing.StringFormat
                    sfCenter.Alignment = Drawing.StringAlignment.Center
                    rectLayout = New Drawing.RectangleF(PrintArgs.MarginBounds.Left, PrintArgs.MarginBounds.Top, PrintArgs.MarginBounds.Width, Font.GetHeight(PrintArgs.Graphics) * Me.m_PageTitle.Split(vbCrLf).Length)
                    PrintArgs.Graphics.DrawString(m_PageTitle, Font, Drawing.Brushes.Black, rectLayout, sfCenter)
                    iThisPageLineCount += Me.m_PageTitle.Split(CChar(vbCrLf)).Length
                End If
    
                'increment one more line to double-space
                iThisPageLineCount += 2
    
                'determine our y position for this row
                yPos = topMargin + iThisPageLineCount * Font.GetHeight(PrintArgs.Graphics)
                'yPos = topMargin + dgv.ColumnHeadersHeight
                For Each c As Windows.Forms.DataGridViewColumn In dgv.Columns
                    If c.Visible Then
    
                        If c.Index < sngColumnPositions.Length - 1 Then
                            rectLayout = New Drawing.RectangleF(sngColumnPositions(c.Index), yPos, sngColumnPositions(c.Index + 1) - sngColumnPositions(c.Index), dgv.ColumnHeadersHeight + iAvgColHeaderChars)
                        Else
                            rectLayout = New Drawing.RectangleF(sngColumnPositions(c.Index), yPos, PrintArgs.MarginBounds.Right - sngColumnPositions(c.Index), dgv.ColumnHeadersHeight + iAvgColHeaderChars)
                        End If
                        sfPlain.LineAlignment = Drawing.StringAlignment.Far
                        PrintArgs.Graphics.DrawString(c.HeaderCell.Value.ToString, Font, Drawing.Brushes.Black, rectLayout, sfPlain)
                        'PrintArgs.Graphics.DrawString(c.HeaderCell.Value, fntBold, Drawing.Brushes.Black, sngColumnPositions(c.Index), yPos, sfPlain)
                    End If
                Next
                iThisPageLineCount += 1
    
                'print each line of the list.
                While iThisPageLineCount < linesPerPage AndAlso m_iPrintIndex < dgv.Rows.Count
    
                    'get this item
                    itmPrint = dgv.Rows(m_iPrintIndex)
    
                    'determine our y position for this row
                    yPos = topMargin + dgv.ColumnHeadersHeight + iAvgColHeaderChars + iThisPageLineCount * Font.GetHeight(PrintArgs.Graphics)
    
                    'print the cells
                    For Each c As Windows.Forms.DataGridViewCell In itmPrint.Cells
                        If c.Visible Then
                            If System.DBNull.Value.Equals(c.Value) Then
                                PrintArgs.Graphics.DrawString(String.Empty, Font, Drawing.Brushes.Black, sngColumnPositions(c.OwningColumn.Index), yPos, sfPlain)
                            ElseIf TypeOf c Is Windows.Forms.DataGridViewCheckBoxCell Then
                                With CType(c, Windows.Forms.DataGridViewCheckBoxCell)
                                    If CBool(.FormattedValue) Then
                                        PrintArgs.Graphics.DrawString("X", Font, Drawing.Brushes.Black, sngColumnPositions(c.OwningColumn.Index), yPos + Font.GetHeight(PrintArgs.Graphics), sfPlain)
                                    End If
                                End With
                            Else
                                If c.OwningColumn.Index < sngColumnPositions.Length - 1 Then
                                    rectLayout = New Drawing.Rectangle(sngColumnPositions(c.OwningColumn.Index), yPos, sngColumnPositions(c.OwningColumn.Index + 1) - sngColumnPositions(c.OwningColumn.Index), Font.GetHeight(PrintArgs.Graphics))
                                Else
                                    rectLayout = New Drawing.Rectangle(sngColumnPositions(c.OwningColumn.Index), yPos, PrintArgs.MarginBounds.Right - sngColumnPositions(c.OwningColumn.Index), Font.GetHeight(PrintArgs.Graphics))
                                End If
                                PrintArgs.Graphics.DrawString(c.FormattedValue, Font, Drawing.Brushes.Black, rectLayout, sfPlain)
                            End If
                        End If
                    Next
    
                    'increment the print counter
                    'and persist it to the print index
                    iThisPageLineCount += 1
                    m_iPrintIndex += 1
    
                End While
    
                ' if more lines exist, print another page.
                PrintArgs.HasMorePages = m_iPrintIndex < dgv.Rows.Count
    
            End Sub
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  3. #3
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: VB2010 windows forms printing question

    Here's a little something to get you started - taken strait from a production app:
    Code:
            Private Sub PrintDataViewGrid(ByRef dgv As Windows.Forms.DataGridView, ByVal PrintArgs As Drawing.Printing.PrintPageEventArgs)
    
                Dim linesPerPage As Single = 0
                Dim yPos As Single = 0
                Dim iThisPageLineCount As Integer = 0
                Dim iPos, iTotalColWidth, iColHeaderChars, iAvgColHeaderChars As Integer
                Dim leftMargin As Single = PrintArgs.MarginBounds.Left
                Dim topMargin As Single = PrintArgs.MarginBounds.Top
                Dim itmPrint As Windows.Forms.DataGridViewRow
                Dim line As String = Nothing
                Dim sngColumnPositions() As Single
                Dim sfPlain As Drawing.StringFormat, sfCenter As Drawing.StringFormat
                Dim rectLayout As Drawing.RectangleF
                Dim FontBold As Drawing.Font
                Dim Font As Drawing.Font
    
                'create any string formats and special fonts
                Font = dgv.Font
                sfPlain = New Drawing.StringFormat
                FontBold = New Drawing.Font(Font, Drawing.FontStyle.Bold)
    
                'calculate the number of lines per page.
                linesPerPage = PrintArgs.MarginBounds.Height / Font.GetHeight(PrintArgs.Graphics)
                'PrintDoc.DefaultPageSettings.Bounds.Height
    
                For Each c As Windows.Forms.DataGridViewColumn In dgv.Columns
                    If c.Visible Then
                        iTotalColWidth += c.Width
                        iColHeaderChars += c.HeaderText.Length
                    End If
                Next
    
                iAvgColHeaderChars = Int(iColHeaderChars / dgv.Columns.Count)
    
                'determine our column positions
                iPos = leftMargin
                ReDim sngColumnPositions(dgv.Columns.Count - 1)
                For Each c As Windows.Forms.DataGridViewColumn In dgv.Columns
                    If c.Visible Then
                        sngColumnPositions(c.Index) = iPos
                        iPos += PrintArgs.MarginBounds.Width * (c.Width / iTotalColWidth)
                    Else
                        sngColumnPositions(c.Index) = iPos
                    End If
                Next
    
    
                'add the page header, if any
                If Me.m_PageTitle.Length > 0 Then
                    sfCenter = New Drawing.StringFormat
                    sfCenter.Alignment = Drawing.StringAlignment.Center
                    rectLayout = New Drawing.RectangleF(PrintArgs.MarginBounds.Left, PrintArgs.MarginBounds.Top, PrintArgs.MarginBounds.Width, Font.GetHeight(PrintArgs.Graphics) * Me.m_PageTitle.Split(vbCrLf).Length)
                    PrintArgs.Graphics.DrawString(m_PageTitle, Font, Drawing.Brushes.Black, rectLayout, sfCenter)
                    iThisPageLineCount += Me.m_PageTitle.Split(CChar(vbCrLf)).Length
                End If
    
                'increment one more line to double-space
                iThisPageLineCount += 2
    
                'determine our y position for this row
                yPos = topMargin + iThisPageLineCount * Font.GetHeight(PrintArgs.Graphics)
                'yPos = topMargin + dgv.ColumnHeadersHeight
                For Each c As Windows.Forms.DataGridViewColumn In dgv.Columns
                    If c.Visible Then
    
                        If c.Index < sngColumnPositions.Length - 1 Then
                            rectLayout = New Drawing.RectangleF(sngColumnPositions(c.Index), yPos, sngColumnPositions(c.Index + 1) - sngColumnPositions(c.Index), dgv.ColumnHeadersHeight + iAvgColHeaderChars)
                        Else
                            rectLayout = New Drawing.RectangleF(sngColumnPositions(c.Index), yPos, PrintArgs.MarginBounds.Right - sngColumnPositions(c.Index), dgv.ColumnHeadersHeight + iAvgColHeaderChars)
                        End If
                        sfPlain.LineAlignment = Drawing.StringAlignment.Far
                        PrintArgs.Graphics.DrawString(c.HeaderCell.Value.ToString, Font, Drawing.Brushes.Black, rectLayout, sfPlain)
                        'PrintArgs.Graphics.DrawString(c.HeaderCell.Value, fntBold, Drawing.Brushes.Black, sngColumnPositions(c.Index), yPos, sfPlain)
                    End If
                Next
                iThisPageLineCount += 1
    
                'print each line of the list.
                While iThisPageLineCount < linesPerPage AndAlso m_iPrintIndex < dgv.Rows.Count
    
                    'get this item
                    itmPrint = dgv.Rows(m_iPrintIndex)
    
                    'determine our y position for this row
                    yPos = topMargin + dgv.ColumnHeadersHeight + iAvgColHeaderChars + iThisPageLineCount * Font.GetHeight(PrintArgs.Graphics)
    
                    'print the cells
                    For Each c As Windows.Forms.DataGridViewCell In itmPrint.Cells
                        If c.Visible Then
                            If System.DBNull.Value.Equals(c.Value) Then
                                PrintArgs.Graphics.DrawString(String.Empty, Font, Drawing.Brushes.Black, sngColumnPositions(c.OwningColumn.Index), yPos, sfPlain)
                            ElseIf TypeOf c Is Windows.Forms.DataGridViewCheckBoxCell Then
                                With CType(c, Windows.Forms.DataGridViewCheckBoxCell)
                                    If CBool(.FormattedValue) Then
                                        PrintArgs.Graphics.DrawString("X", Font, Drawing.Brushes.Black, sngColumnPositions(c.OwningColumn.Index), yPos + Font.GetHeight(PrintArgs.Graphics), sfPlain)
                                    End If
                                End With
                            Else
                                If c.OwningColumn.Index < sngColumnPositions.Length - 1 Then
                                    rectLayout = New Drawing.Rectangle(sngColumnPositions(c.OwningColumn.Index), yPos, sngColumnPositions(c.OwningColumn.Index + 1) - sngColumnPositions(c.OwningColumn.Index), Font.GetHeight(PrintArgs.Graphics))
                                Else
                                    rectLayout = New Drawing.Rectangle(sngColumnPositions(c.OwningColumn.Index), yPos, PrintArgs.MarginBounds.Right - sngColumnPositions(c.OwningColumn.Index), Font.GetHeight(PrintArgs.Graphics))
                                End If
                                PrintArgs.Graphics.DrawString(c.FormattedValue, Font, Drawing.Brushes.Black, rectLayout, sfPlain)
                            End If
                        End If
                    Next
    
                    'increment the print counter
                    'and persist it to the print index
                    iThisPageLineCount += 1
                    m_iPrintIndex += 1
    
                End While
    
                ' if more lines exist, print another page.
                PrintArgs.HasMorePages = m_iPrintIndex < dgv.Rows.Count
    
            End Sub
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: VB2010 windows forms printing question


  5. #5
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: VB2010 windows forms printing question

    Here's a little something to get you started - taken strait from a production app:
    Code:
            Private Sub PrintDataViewGrid(ByRef dgv As Windows.Forms.DataGridView, ByVal PrintArgs As Drawing.Printing.PrintPageEventArgs)
    
                Dim linesPerPage As Single = 0
                Dim yPos As Single = 0
                Dim iThisPageLineCount As Integer = 0
                Dim iPos, iTotalColWidth, iColHeaderChars, iAvgColHeaderChars As Integer
                Dim leftMargin As Single = PrintArgs.MarginBounds.Left
                Dim topMargin As Single = PrintArgs.MarginBounds.Top
                Dim itmPrint As Windows.Forms.DataGridViewRow
                Dim line As String = Nothing
                Dim sngColumnPositions() As Single
                Dim sfPlain As Drawing.StringFormat, sfCenter As Drawing.StringFormat
                Dim rectLayout As Drawing.RectangleF
                Dim FontBold As Drawing.Font
                Dim Font As Drawing.Font
    
                'create any string formats and special fonts
                Font = dgv.Font
                sfPlain = New Drawing.StringFormat
                FontBold = New Drawing.Font(Font, Drawing.FontStyle.Bold)
    
                'calculate the number of lines per page.
                linesPerPage = PrintArgs.MarginBounds.Height / Font.GetHeight(PrintArgs.Graphics)
                'PrintDoc.DefaultPageSettings.Bounds.Height
    
                For Each c As Windows.Forms.DataGridViewColumn In dgv.Columns
                    If c.Visible Then
                        iTotalColWidth += c.Width
                        iColHeaderChars += c.HeaderText.Length
                    End If
                Next
    
                iAvgColHeaderChars = Int(iColHeaderChars / dgv.Columns.Count)
    
                'determine our column positions
                iPos = leftMargin
                ReDim sngColumnPositions(dgv.Columns.Count - 1)
                For Each c As Windows.Forms.DataGridViewColumn In dgv.Columns
                    If c.Visible Then
                        sngColumnPositions(c.Index) = iPos
                        iPos += PrintArgs.MarginBounds.Width * (c.Width / iTotalColWidth)
                    Else
                        sngColumnPositions(c.Index) = iPos
                    End If
                Next
    
    
                'add the page header, if any
                If Me.m_PageTitle.Length > 0 Then
                    sfCenter = New Drawing.StringFormat
                    sfCenter.Alignment = Drawing.StringAlignment.Center
                    rectLayout = New Drawing.RectangleF(PrintArgs.MarginBounds.Left, PrintArgs.MarginBounds.Top, PrintArgs.MarginBounds.Width, Font.GetHeight(PrintArgs.Graphics) * Me.m_PageTitle.Split(vbCrLf).Length)
                    PrintArgs.Graphics.DrawString(m_PageTitle, Font, Drawing.Brushes.Black, rectLayout, sfCenter)
                    iThisPageLineCount += Me.m_PageTitle.Split(CChar(vbCrLf)).Length
                End If
    
                'increment one more line to double-space
                iThisPageLineCount += 2
    
                'determine our y position for this row
                yPos = topMargin + iThisPageLineCount * Font.GetHeight(PrintArgs.Graphics)
                'yPos = topMargin + dgv.ColumnHeadersHeight
                For Each c As Windows.Forms.DataGridViewColumn In dgv.Columns
                    If c.Visible Then
    
                        If c.Index < sngColumnPositions.Length - 1 Then
                            rectLayout = New Drawing.RectangleF(sngColumnPositions(c.Index), yPos, sngColumnPositions(c.Index + 1) - sngColumnPositions(c.Index), dgv.ColumnHeadersHeight + iAvgColHeaderChars)
                        Else
                            rectLayout = New Drawing.RectangleF(sngColumnPositions(c.Index), yPos, PrintArgs.MarginBounds.Right - sngColumnPositions(c.Index), dgv.ColumnHeadersHeight + iAvgColHeaderChars)
                        End If
                        sfPlain.LineAlignment = Drawing.StringAlignment.Far
                        PrintArgs.Graphics.DrawString(c.HeaderCell.Value.ToString, Font, Drawing.Brushes.Black, rectLayout, sfPlain)
                        'PrintArgs.Graphics.DrawString(c.HeaderCell.Value, fntBold, Drawing.Brushes.Black, sngColumnPositions(c.Index), yPos, sfPlain)
                    End If
                Next
                iThisPageLineCount += 1
    
                'print each line of the list.
                While iThisPageLineCount < linesPerPage AndAlso m_iPrintIndex < dgv.Rows.Count
    
                    'get this item
                    itmPrint = dgv.Rows(m_iPrintIndex)
    
                    'determine our y position for this row
                    yPos = topMargin + dgv.ColumnHeadersHeight + iAvgColHeaderChars + iThisPageLineCount * Font.GetHeight(PrintArgs.Graphics)
    
                    'print the cells
                    For Each c As Windows.Forms.DataGridViewCell In itmPrint.Cells
                        If c.Visible Then
                            If System.DBNull.Value.Equals(c.Value) Then
                                PrintArgs.Graphics.DrawString(String.Empty, Font, Drawing.Brushes.Black, sngColumnPositions(c.OwningColumn.Index), yPos, sfPlain)
                            ElseIf TypeOf c Is Windows.Forms.DataGridViewCheckBoxCell Then
                                With CType(c, Windows.Forms.DataGridViewCheckBoxCell)
                                    If CBool(.FormattedValue) Then
                                        PrintArgs.Graphics.DrawString("X", Font, Drawing.Brushes.Black, sngColumnPositions(c.OwningColumn.Index), yPos + Font.GetHeight(PrintArgs.Graphics), sfPlain)
                                    End If
                                End With
                            Else
                                If c.OwningColumn.Index < sngColumnPositions.Length - 1 Then
                                    rectLayout = New Drawing.Rectangle(sngColumnPositions(c.OwningColumn.Index), yPos, sngColumnPositions(c.OwningColumn.Index + 1) - sngColumnPositions(c.OwningColumn.Index), Font.GetHeight(PrintArgs.Graphics))
                                Else
                                    rectLayout = New Drawing.Rectangle(sngColumnPositions(c.OwningColumn.Index), yPos, PrintArgs.MarginBounds.Right - sngColumnPositions(c.OwningColumn.Index), Font.GetHeight(PrintArgs.Graphics))
                                End If
                                PrintArgs.Graphics.DrawString(c.FormattedValue, Font, Drawing.Brushes.Black, rectLayout, sfPlain)
                            End If
                        End If
                    Next
    
                    'increment the print counter
                    'and persist it to the print index
                    iThisPageLineCount += 1
                    m_iPrintIndex += 1
    
                End While
    
                ' if more lines exist, print another page.
                PrintArgs.HasMorePages = m_iPrintIndex < dgv.Rows.Count
    
            End Sub
    NOTE: This .net version 2.0 - there may be better ways in newer versions. I know this works, though.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    Re: VB2010 windows forms printing question

    The examples you are posting, I believe, are strictly for data grid view, my form has a mixture of items on it. I am including an image of it.
    Name:  Capture.JPG
Views: 974
Size:  135.7 KB

    The form scrolls down for another 10 controls or so.

    Thank you,

    Steve

  7. #7
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: VB2010 windows forms printing question

    I apologize - I misread your earlier post. However, the code I posted will give you a place to get started on printing. I don't know that there's a simple solution to what you're looking for. You may just have to code it out. If so, then hopefully when you're done you'll have a nice neat solution to share with the rest of us.

    But maybe... Somebody else will chime in with something easier.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: VB2010 windows forms printing question

    As dolot guessed, there is no simple solution.

  9. #9
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: VB2010 windows forms printing question

    There is a component I wrote called MCLFormPrint that will do pretty much all of this except data grids, which I never got around to doing - however you could add the code from this article to do the data grid part.

    I also wrote a short e-book on printing in .NET that should also help.

  10. #10
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: VB2010 windows forms printing question

    There you go... take all of Merion's info and put it together and you'll have a great, all purpose printing control. Then you can post it online for everyone to benefit from... I know I'll download it... nice component to a bag of tricks.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  11. #11
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: VB2010 windows forms printing question

    Yup - if you want to use MCLFormPrint as your starting point I can add you as a developer in CodePlex. (Applies to anyone so minded)

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    Re: VB2010 windows forms printing question

    Yes, I would like that.

    Guess I am a little surprised that visual studio didn't already have a simpler way to do this.

    Thank you,

    Steve

    Quote Originally Posted by Merrion View Post
    Yup - if you want to use MCLFormPrint as your starting point I can add you as a developer in CodePlex. (Applies to anyone so minded)

  13. #13
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: VB2010 windows forms printing question

    Even in classic VB, printing was a weakness. Not real sure why.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  14. #14
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: VB2010 windows forms printing question

    If your going to be printing reports I would suggest using a reporting tool like Reportviewer or Crystal Reports or what meets your needs, there are a lot of different ones. The two I listed are probably the most used and you will be able to find many examples and help.

  15. #15

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    Re: VB2010 windows forms printing question

    I will be using SSRS for reporting, just need something to print off current record for their paper folder.


    Quote Originally Posted by wes4dbt View Post
    If your going to be printing reports I would suggest using a reporting tool like Reportviewer or Crystal Reports or what meets your needs, there are a lot of different ones. The two I listed are probably the most used and you will be able to find many examples and help.

  16. #16
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: VB2010 windows forms printing question

    Printing is (quite) difficult but in truth MS could have made it easier with a print designer analogous to the form designer....

  17. #17
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: VB2010 windows forms printing question

    Quote Originally Posted by Merrion View Post
    Printing is (quite) difficult but in truth MS could have made it easier with a print designer analogous to the form designer....
    A print designer would be a useful tool, but would be difficult to implement because of scrollable controls.
    I'd be interested to see that put into practice, + Microsoft might even use it in the next version of VS...

  18. #18
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: VB2010 windows forms printing question

    For scrollable controls I have settings to either truncate it to fit or start a new page (DataOverflowAction

  19. #19
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: VB2010 windows forms printing question

    If you consider it further there are at least 3 problem areas: datagridviews, listviews, + richtextboxes, all of which are complex printing jobs individually

  20. #20
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: VB2010 windows forms printing question

    I haven't had a look at your printing code yet, but I will when I have some free time

  21. #21
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: VB2010 windows forms printing question

    Cool. It does do RTF boxes across multiple pages.

  22. #22
    Member
    Join Date
    Mar 2009
    Posts
    61

    Re: VB2010 windows forms printing question

    I just posted code about printing tabpages with scroll bars, with some edits the code will also work with you requirements...

    http://www.vbforums.com/showthread.p...Please-net-4-5

    BR
    Phezo

  23. #23
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: VB2010 windows forms printing question

    I will be using SSRS for reporting, just need something to print off current record for their paper folder.
    Seems like a perfect little report to learn how to create SSRS reports. It's probably easier and faster to learn than creating a report manually.

  24. #24

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    Re: VB2010 windows forms printing question

    Can you launch a SSRS report for a particular record? I have only used it on full datasets to date with some filtering parameters.

    Thank you,

    Steve

    Quote Originally Posted by wes4dbt View Post
    Seems like a perfect little report to learn how to create SSRS reports. It's probably easier and faster to learn than creating a report manually.

  25. #25
    Member
    Join Date
    Mar 2009
    Posts
    61

    Re: VB2010 windows forms printing question

    Quote Originally Posted by shathaway View Post
    Can you launch a SSRS report for a particular record? I have only used it on full datasets to date with some filtering parameters.

    Thank you,

    Steve
    Yes you can, google "ssrs report passing parameters" :-)

    BR
    Phezo

  26. #26

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    Re: VB2010 windows forms printing question

    I am having problems getting the report to accept it or recognize it.

    This is the URL I am using, Report parameter
    CandidateID
    parameter visibility = hidden
    available values = none
    default values = none

    error = The 'CandidateID' parameter is missing a value

    If I do parameter visibility = Internal

    I get the following error = Parameter validation failed. It is not possible to provide valid values for all parameters. (rsParameterError)


    http://bfufsdbfcrpt1/Reports/Pages/R...&CandidateID=7


    should I be using hidden or internal? Any idea on the errors?


    Quote Originally Posted by phezo View Post
    Yes you can, google "ssrs report passing parameters" :-)

    BR
    Phezo

  27. #27
    Member
    Join Date
    Mar 2009
    Posts
    61

    Re: VB2010 windows forms printing question

    http://www.youtube.com/watch?v=yMyHAg60NPA

    Try watching this


    This will explain a simple way to setup report parameters, remember you can supply multiple datasources to one report...

    BR
    Phezo

  28. #28

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    Re: VB2010 windows forms printing question

    Got it figured out. I needed the server/Reports to be server/reportserver.

    The way I was accessing the link(url) wouldn't allow parameters to be passed in.

  29. #29
    Member
    Join Date
    Mar 2009
    Posts
    61

    Re: VB2010 windows forms printing question

    Great work...

    Glad to see you are progressing :-)

    BR
    Phezo

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width