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. C#
  4. Printing a windowsform

Printing a windowsform

Scheduled Pinned Locked Moved C#
csharptutorial
6 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.
  • M Offline
    M Offline
    mrcsn
    wrote on last edited by
    #1

    Hi , how can we print a windows form in C# using print document control ....., im not getting how to assign printdocument1.document= form(); thanks .

    A G 2 Replies Last reply
    0
    • M mrcsn

      Hi , how can we print a windows form in C# using print document control ....., im not getting how to assign printdocument1.document= form(); thanks .

      A Offline
      A Offline
      Ajay k_Singh
      wrote on last edited by
      #2

      Hello, You may take a snapshot of Form using PrintToBitmap function of Form. Following is a code snippet to do so- --------------- bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); this.DrawToBitmap(bmp, new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width, this.ClientRectangle.Height)); this.PictureBox2.Image = bmp; --------------- If you want to print this data then you will need to add one PrintDocument object, like this- Dim WithEvents pdoc As New System.Drawing.Printing.PrintDocument Add code in PrintPage Event of PrintDocument object – e.Graphics.DrawImage(bmp, this.ClientRectangle.X, this.ClientRectangle.Y); Then you may get it printed by simply using a line of code- pdoc.Print(); This would print the picture of the form. I hope this helps. -Dave.

      Dave Traister, ComponentOne LLC. www.componentone.com

      M 1 Reply Last reply
      0
      • M mrcsn

        Hi , how can we print a windows form in C# using print document control ....., im not getting how to assign printdocument1.document= form(); thanks .

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        Do you know How to use Google[^]? Here are some of the search results: Print Windows Forms w/o using API[^] Form Print Control[^]

        Giorgi Dalakishvili #region signature my articles #endregion

        1 Reply Last reply
        0
        • A Ajay k_Singh

          Hello, You may take a snapshot of Form using PrintToBitmap function of Form. Following is a code snippet to do so- --------------- bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height); this.DrawToBitmap(bmp, new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width, this.ClientRectangle.Height)); this.PictureBox2.Image = bmp; --------------- If you want to print this data then you will need to add one PrintDocument object, like this- Dim WithEvents pdoc As New System.Drawing.Printing.PrintDocument Add code in PrintPage Event of PrintDocument object – e.Graphics.DrawImage(bmp, this.ClientRectangle.X, this.ClientRectangle.Y); Then you may get it printed by simply using a line of code- pdoc.Print(); This would print the picture of the form. I hope this helps. -Dave.

          Dave Traister, ComponentOne LLC. www.componentone.com

          M Offline
          M Offline
          mrcsn
          wrote on last edited by
          #4

          HI , Thanks for u r reply , what im trying is , ihave a form containg textboxes and labels , i want to print that form as it is . can you tell me how can i do this .............

          A 1 Reply Last reply
          0
          • M mrcsn

            HI , Thanks for u r reply , what im trying is , ihave a form containg textboxes and labels , i want to print that form as it is . can you tell me how can i do this .............

            A Offline
            A Offline
            Ajay k_Singh
            wrote on last edited by
            #5

            I have already informed you, take image of form in a bitmap object usign DrawToBitmap function, and print this form using PrintDocument control. If you want to print only some of the controls, use DrawToBitmap function of those controls to draw them in different bitmap objects, because every control comes with this method. -Dave.

            Dave Traister, ComponentOne LLC. www.componentone.com

            M 1 Reply Last reply
            0
            • A Ajay k_Singh

              I have already informed you, take image of form in a bitmap object usign DrawToBitmap function, and print this form using PrintDocument control. If you want to print only some of the controls, use DrawToBitmap function of those controls to draw them in different bitmap objects, because every control comes with this method. -Dave.

              Dave Traister, ComponentOne LLC. www.componentone.com

              M Offline
              M Offline
              mrcsn
              wrote on last edited by
              #6

              OK , Thank you i will try

              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