c#printdocument添加空白行代码
时间: 2023-12-22 14:04:45 浏览: 211
您可以使用`\n`或`Environment.NewLine`来添加空白行。以下是示例代码:
```csharp
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
string text = "This is some text.\n\nThis will be on a new line.";
// 绘制文本
e.Graphics.DrawString(text, new Font("Arial", 12), Brushes.Black, 10, 10);
}
```
在上面的示例中,`\n`被用作两个段落之间的空白行。您还可以使用`Environment.NewLine`,如下所示:
```csharp
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
string text = "This is some text." + Environment.NewLine + Environment.NewLine + "This will be on a new line.";
// 绘制文本
e.Graphics.DrawString(text, new Font("Arial", 12), Brushes.Black, 10, 10);
}
```
使用`Environment.NewLine`可以确保在不同操作系统上正确地添加空白行。
阅读全文