Comment insérer le contenu à imprimer dans les instructions du bouton imprimer en CSHAP ?
- User
Comment insérer le contenu à imprimer dans les instructions du bouton imprimer en CSHAP ?
- Assistant
Pour insérer du contenu à imprimer dans les instructions du bouton imprimer en C#, vous pouvez utiliser la classe PrintDocument. Voici un exemple de code qui montre comment imprimer du contenu à partir d'un bouton :
csharpprivate void btnImprimer_Click(object sender, EventArgs e) { PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage); PrintDialog pdialog = new PrintDialog(); pdialog.Document = pd; if (pdialog.ShowDialog() == DialogResult.OK) { pd.Print(); } } private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) { // Insérer ici le contenu à imprimer, par exemple un texte ou une image e.Graphics.DrawString("Contenu à imprimer", new Font("Arial", 12), Brushes.Black, 100, 100); }