我不确定这是否是你想要的,但是,
您要做的是创建一个虚拟表单,该表单与您要打印的控件的大小相同,然后将控件添加到虚拟表单并显示表单并在虚拟表单上打印控件。
我是这样做的:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Create bitmap
Bitmap image = new Bitmap(dataGridView1.Width, dataGridView1.Height);
//Create form
Form f = new Form();
//add datagridview to the form
f.Controls.Add(dataGridView1);
//set the size of the form to the size of the datagridview
f.Size = dataGridView1.Size;
//draw the datagridview to the bitmap
dataGridView1.DrawToBitmap(image, new Rectangle(0, 0, dataGridView1.Width, dataGridView1.Height));
//dispose the form
f.Dispose();
//print
e.Graphics.DrawImage(image, 0, 0);
}
这将打印 dataGridView1,即使它在表单上看不到。