Printing a windowsform
-
Hi , how can we print a windows form in C# using print document control ....., im not getting how to assign printdocument1.document= form(); thanks .
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
-
Hi , how can we print a windows form in C# using print document control ....., im not getting how to assign printdocument1.document= form(); thanks .
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
-
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
-
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 .............
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
-
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