PrintDocument將是要走的路。它使用GDI+
來繪製到文檔的表面。您現在負責佈局。
private void pd_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
{
single yPos = 0;
int count = 0;
single leftMargin = e.MarginBounds.Left;
single topMargin = e.MarginBounds.Top;
Image img = Image.FromFile({path to img});
Rectangle logo = New Rectangle(40,40,50,50);
using (Font printFont = new Font("Arial", 10.0f))
{
e.Graphics.DrawImage(img, logo);
e.Graphics.DrawString(textbox1.Text, printFont, Brushes.Black, leftMargin, yPos, New StringFormat());
}
//etc...
//taken from the example and added how to draw the text from a textbox
}
謝謝!我會如何去添加一個簡單的文本框來打印我的文檔?我沒有看到在提供的鏈接中添加控件的任何示例 – Nathan
@ user2856410您無法「添加」文本框。您可以在任意位置的表面上繪製文字。 –
我可以添加圖片嗎? – Nathan