Bonjour,
je suis débutant en c#, j'ai fait une appli qui permet d'imprimer le contenu d'une picturebox. Une foi la photo imprimé, je fais disparaître le bouton imprimer et réapparaître le bouton de sélection de photo une foi la photo sélectionnée, le bouton imprimer réapparaît. Lorsque j'essai d'imprimer pour la troisième fois j'ai une exception sur graphics.drawing.
commentaires:
1- si je n'utilse pas de timer, j'ai des exceptions (ArgumentsNullException) idem pour Thread.Sleep
2- le if flag =0 est la car je ne sais pas pourquoi mais la première foi que j'appui sur imprimer le code se lance 1 fois, la 2eme, 2 fois, la 3eme, 3 fois,.....
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
65
66
67
68
69 private void Print_Click(object sender3, EventArgs e3) { if (flag == 0) { myTimer3.Tick += new EventHandler(Timer3); flag = 1; myTimer3.Interval = 5; } myTimer3.Start(); } private void Timer3(Object myObject3, EventArgs myEventArgs3) { try { myTimer3.Stop(); myTimer3.Dispose(); Recom.Visible = false; Print.Visible = false; panel1.BackgroundImage = null; panel1.BackgroundImage = Image.FromFile("E:/livre/conf/loading.gif"); pictureBox2.Visible = false; pictureBox5.Visible = false; Thread.Sleep(interval2); imprimer(); debut(); } catch (Exception ex) { MessageBox.Show( ex.ToString()); } } private void imprimer() { pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); pd.PrintPage += null; pd.Print(); pd.Dispose(); } private void pd_PrintPage(object senderP, System.Drawing.Printing.PrintPageEventArgs ev) { try { MessageBox.Show("1"); ev.Graphics.DrawImage(this.pictureBox5.Image, 0, 0, 390, 300); ev.HasMorePages = false; ev.Graphics.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }Merci de m'aiderException:
SystemAccessViolation ev.Graphics.Drawing dans la fonction pd_printpage
Partager