Matthew Bagley

Matthew Bagley

  • 2.2k
  • 1
  • 6k

Printing the active form in C# without the title bar and frame

Aug 5 2010 8:06 AM
Hey guys i'm stuck on this one, I'm trying to print the contents of a windows form, I am able to print the entire windows form but this then shows the form title, title bar and frame this is not what I want.

How would I go around doing this?  An ugly method is to change the frame border of the form to none and then change it back once printed but this is terrible.

My current code is as follows:
 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
using System.Drawing.Printing;
using System.Runtime.InteropServices;

namespace printSample
public partial class Form2 : Form

public Form2()

void PrintImage(object o, PrintPageEventArgs e)
int x = SystemInformation.WorkingArea.X;
int y = SystemInformation.WorkingArea.Y;
int width = this.Width;
int height = this.Height;

Rectangle bounds = new Rectangle(x, y, width, height);
Bitmap img = new Bitmap(width, height);

this.DrawToBitmap(img, bounds);
Point p = new Point(100, 100);
e.Graphics.DrawImage(img, p);

private void button1_Click(object sender, EventArgs e)
//this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
PrintDocument pd = new PrintDocument();

pd.PrintPage += new PrintPageEventHandler(PrintImage);

printPreviewDialog1.Document = pd;
// this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;


private void button2_Click(object sender, EventArgs e)
MessageBox.Show(this.Width + " - " + SystemInformation.FrameBorderSize.Width);


Answers (2)