Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Print a Formm

Print a Formm

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Trupti Mehta
    wrote on last edited by
    #1

    Hi, Is it possible to print a Windows Form? I have a form that needs to be printed. I am not dealing with data source, but values objects. I am using VB .NET 2005. If a form cannot be printed, then what best approach is possible to give some results to print. Their is no Data Source. Just display values from objects, prepare a descent form and print it. Any help is highly appreciated. Thanks Trupti

    Thanks Terry

    D J 2 Replies Last reply
    0
    • T Trupti Mehta

      Hi, Is it possible to print a Windows Form? I have a form that needs to be printed. I am not dealing with data source, but values objects. I am using VB .NET 2005. If a form cannot be printed, then what best approach is possible to give some results to print. Their is no Data Source. Just display values from objects, prepare a descent form and print it. Any help is highly appreciated. Thanks Trupti

      Thanks Terry

      D Offline
      D Offline
      Duncan Edwards Jones
      wrote on last edited by
      #2

      Something like the Form Print Control[^] might be of use?

      '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

      1 Reply Last reply
      0
      • T Trupti Mehta

        Hi, Is it possible to print a Windows Form? I have a form that needs to be printed. I am not dealing with data source, but values objects. I am using VB .NET 2005. If a form cannot be printed, then what best approach is possible to give some results to print. Their is no Data Source. Just display values from objects, prepare a descent form and print it. Any help is highly appreciated. Thanks Trupti

        Thanks Terry

        J Offline
        J Offline
        JamesS C1
        wrote on last edited by
        #3

        Hello Trupti, Printing in Windows Forms consists primarily of using the PrintDocument Component (Windows Forms) component to enable the user to print, and the PrintPreviewDialog Control (Windows Forms) control, PrintDialog Component (Windows Forms) and PageSetupDialog Component (Windows Forms) components to provide a familiar graphical interface to users accustomed to the Windows operating system. Typically, you create a new instance of the PrintDocument component, set the properties that describe what to print using the PrinterSettings and PageSettings classes, and call the Print method to actually print the document. During the course of printing from a Windows-based application, the PrintDocument component will show an abort print dialog box to alert users to the fact that printing is occurring and to allow the print job to be canceled. The foundation of printing in Windows Forms is the PrintDocument component—more specifically, the PrintPage event. By writing code to handle the PrintPage event, you can specify what to print and how to print it. To create a print job: 1. Add a PrintDocument component to your form. 2. Write code to handle the PrintPage event. You will have to code your own printing logic. Additionally, you will have to specify the material to be printed. In the following code example, a sample graphic in the shape of a red rectangle is created in the PrintPage event handler to act as material to be printed. Visual Basic Copy Code Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage e.Graphics.FillRectangle(Brushes.Red, New Rectangle(500, 500, 500, 500)) End Sub C# Copy Code private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.FillRectangle(Brushes.Red, new Rectangle(500, 500, 500, 500)); } J# Copy Code private void printDocument1_PrintPage(Object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.get_Graphics().FillRectangle(Brushes.get_Red(), new Rectangle(500, 500, 500, 500)); } C++ Copy Code private: void printDocument1_PrintPage(System::Object ^ sender, System::Drawing::Printing::PrintPageEventArgs ^ e) { e->Graphics->FillRectangle(Brushes::Red, Rectangle(500, 500, 500, 500)); } (Visual C#, Visual J# and Visual C++) Place the following code in the form's constructor to register the event handler. C

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups