我有一个窗体。我想打印没有窗口外观的表单内容。我的意思是我想像收据一样打印它,没有窗口边框。我该怎么做呢?
问问题
7409 次
2 回答
1
您可以参考 MSDN 示例,了解如何打印到 Windows 窗体,将正在打印的表面从窗体更改为面板控件,这将使您能够无边框打印。您的内容必须添加到面板而不是表单,但它会起作用。这是 MSDN 示例的修改示例。
public class Form1 : Form
{
private Panel printPanel = new Panel();
private Button printButton = new Button();
private PrintDocument printDocument1 = new PrintDocument();
public Form1()
{
printPanel.Size = this.ClientSize;
this.Controls.Add(printPanel);
printButton.Text = "Print Form";
printButton.Click += new EventHandler(printButton_Click);
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
printPanel.Controls.Add(printButton);
}
void printButton_Click(object sender, EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
Bitmap memoryImage;
private void CaptureScreen()
{
Graphics myGraphics = printPanel.CreateGraphics();
Size s = printPanel.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
Point screenLoc = PointToScreen(printPanel.Location); // Get the location of the Panel in Screen Coordinates
memoryGraphics.CopyFromScreen(screenLoc.X, screenLoc.Y, 0, 0, s);
}
private void printDocument1_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
public static void Main()
{
Application.Run(new Form1());
}
}
于 2012-06-10T06:27:20.800 回答
-1
你可以通过做这样的事情来获得一个空白屏幕
this.FormBorderStyle = System.Windows.Forms.FormsBorderStyle.None;
this.ControlBox = false;
this.Text = String.Empty;
于 2012-06-10T04:48:19.097 回答