Bonsoir,
Voilà mon problème:
J'ai un winForm avec un RichTextBox, un bouton 'Imprimer' et un bouton 'Quitter'. J'arrive avec le code à écrire et à dessiner sur mon RichTextBox (appelé 'Page') via un objet Graphics mais lorsque je demande d'afficher le PrintPreviewDialog, il m'affiche une page blanche ?!!!
Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
namespace FormulairesGDI
{
    public partial class Form1 : Form
    {
        PrintDocument myDocument;
        Graphics monGr;
 
        public Form1()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            Invalidate();
        }
 
         private void Form1_Load(object sender, EventArgs e)
        {
            myDocument = new PrintDocument();
            myDocument.DefaultPageSettings.Margins.Top = 50;
            myDocument.DefaultPageSettings.Margins.Left = 50;
            myDocument.DefaultPageSettings.Margins.Right = 50;
            myDocument.DefaultPageSettings.Landscape = false;
            myDocument.DocumentName = Page.Text;
            myDocument.PrintPage += new PrintPageEventHandler(myDocument_PrintPage);
        }
 
        void myDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            monGr = Page.CreateGraphics();
            //Style et police avec lesquels on va écrire
            Font myFont = new Font("Arial",10);
            //Choix de la couleur
            Brush printColor = Brushes.Red ;
            //Ecriture
            monGr.DrawString("Impression avec .Net",myFont, printColor,10,10);
            monGr.DrawRectangle(Pens.Blue, 9, 9, 150, 150);
            monGr.Dispose();
        }
 
        private void btnQuitter_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
 
        private void btnImprimer_Click(object sender, EventArgs e)
        {
            printPreviewDialog1.Document = myDocument;
            printPreviewDialog1.ShowDialog();
        }
 
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            monGr = Page.CreateGraphics();
            //Style et police avec lesquels on va écrire
            Font myFont = new Font("Arial", 10);
            //Choix de la couleur
            Brush printColor = Brushes.Black;
            //Ecriture
            monGr.DrawString("Impression avec .Net", myFont, printColor, 10, 10);
            monGr.DrawRectangle(Pens.Blue, 9, 9, 150, 150);
            monGr.Dispose();
        }
     }
}
Quelqu'un pourrait-il m'éclairer ?