Results 1 to 5 of 5

Thread: Printing Form with labels

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Printing Form with labels

    Hi,

    Can some one pls tell me how to print a form with labels.The code Ive tried is like this:


    VB Code:
    1. Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
    2.            ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
    3.            pd1.PrintPage
    4.         Dim myPaintArgs As New PaintEventArgs(e.Graphics, New Rectangle(New _
    5.            Point(0, 0), Me.Size))
    6.         Dim ctl As Control
    7.         Static fntHeadingFont As New Font("Arial", 12, FontStyle.Bold)
    8.  
    9.         Try
    10.             For Each ctl In Me.Controls
    11.                 If TypeOf ctl Is Label Then
    12.                     'Me.InvokePaint(Me, myPaintArgs)
    13.                     'I need to get the object to print all labels on page in the exact postion
    14.                 End If
    15.             Next
    16.  
    17.             e.HasMorePages = False
    18.         Catch ex As Exception
    19.             MessageBox.Show("An error occurred while printing", _
    20.                 ex.ToString())
    21.         End Try
    22.  
    23.     End Sub
    24.  
    25.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    26.         PrintPreviewDialog1.ShowDialog()
    27.        
    28.    End Sub
    29.  
    30.  
    31.     Private Sub printbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printbutton.Click
    32.         Try
    33.             pd1.Print()
    34.         Catch ex As Exception
    35.             MessageBox.Show("An error occurred while printing", _
    36.                 ex.ToString())
    37.         End Try
    38.     End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Printing Form with labels

    I suggest that you forget printing Labels. Print the text that is in the Labels. You have the Size, Location, Text and Font properties of all the Labels so use those to just print text.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Printing Form with labels

    or print the entire form as an image with the help provided in my sig
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Printing Form with labels

    hi,

    As with jmcilhinney, can u give me an example. pls cos

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Printing Form with labels

    The 2003 101 Samples contains a printing example. See my signature for a link if you want to go that way.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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