Impression

Signaler
-
Bonjour,
Je voudrais imprimer un pdf avec chois d'imprimante en construisant ma propre boite de dialogue voici mon code qui n'imprime rien !!
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Printing;



namespace facturation1
{
public partial class Form1 : Form
{
private string[] lignes;
private int lignesImprime;


public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{

OpenFileDialog openFile = new OpenFileDialog();
openFile.DefaultExt = "";
openFile.Filter = "RichTextFormat|*.rtf|Textes|*.txt"; ; // Filter les fichiers par extension


if ( openFile.ShowDialog() == DialogResult.OK)
{
try
{
if ( openFile.FilterIndex == 1)
{
//LoadFile pour un RTF

textBox1.Text = openFile.FileName;
}
else
{
//Il faut un StreamReader sinon
StreamReader Lire = new StreamReader( openFile.FileName);
textBox1.Text = Lire.ReadToEnd();
Lire.Close();
}
}
catch (System.Exception err)
{
MessageBox.Show("Erreur à l'ouverture:\n" + err.Message, "Erreur");
}
}






foreach (string printer in PrinterSettings.InstalledPrinters)
{
comboBox1.Items.Add(printer);
}



}



private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
//Marges
int x = e.MarginBounds.Left;
int y = e.MarginBounds.Top;

//Dessine chaque ligne
while (lignesImprime < lignes.Length)
{
e.Graphics.DrawString(lignes[lignesImprime++], new Font("Arial", 10),
Brushes.Black, x, y);
y += 15;
if (y >= e.MarginBounds.Bottom)
{
e.HasMorePages = true;
return;
}
}
lignesImprime = 0;
e.HasMorePages = false;
}



private void button2_Click(object sender, EventArgs e)
{

printDocument1.PrinterSettings.PrinterName = comboBox1.SelectedText;
printDocument1.TextTo();


printDocument1.Print();

}



}
}