It is necessary that the questions method be executed by clicking a button.
However, it must be executed in printDocument1_PrintPage .
Thank you in advance
namespace WindowsFormsApplication1 { public partial class Form1 : Form { private int currentPage = 1; public Form1() { InitializeComponent(); } private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { questions(e); } private void questions(PrintPageEventArgs e) { FileStream file = new FileStream("e:\\test.txt", FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(file); string c = reader.ReadToEnd(); string[] array = c.Split('\n'); reader.Close(); Font font = new Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); Graphics g = e.Graphics; StringFormat format1 = new StringFormat(); format1.Trimming = StringTrimming.EllipsisWord; if (this.currentPage <= numericUpDown1.Value) { foreach (var item in array) { g.DrawString(item/*+ this.currentPage*/, font, System.Drawing.Brushes.Black, new RectangleF(10, 10, 820, 1000), format1); } this.currentPage++; e.HasMorePages = true; } if (this.currentPage > numericUpDown1.Value) { currentPage = 1; e.HasMorePages = false; } printPreviewControl1.Rows = 20; } private void button2_Click(object sender, EventArgs e) { //this.printDocument1.Print(); } } }