Bonjour tout le monde,

j'ai une première fenêtre ("SuiviIntervention") que je souhaite imprimer en transvasant ses données dans une deuxième forms ("Form2").

Voici le code que j'utilise dans la première form :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
private void Imprimer_Click(object sender, System.EventArgs e)
		{
Form2 F2 = new Form2();
			F2.UpdateValues(dataGrid1);
			F2.ShowDialog();
		}
Et voici le code que j'utilise dans la deuxième form :
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
using System.Drawing.Printing;
 
private const int WM_PRINT = 0x0317;
		private const int PRF_CLIENT = 0x00000004;
		private const int PRF_CHILDREN = 0x00000010;
 
		public void UpdateValues(string DG)
		{
			dataGrid1.Show();
		}
 
		public Bitmap PrintWindowEx()
		{
			Bitmap bmp = null;
			Graphics gr = null;
			IntPtr hdc = IntPtr.Zero;
			try
			{
				bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, this.CreateGraphics());
				gr = Graphics.FromImage(bmp);
				hdc = gr.GetHdc();
				IntPtr wParam = hdc;
				IntPtr lParam = new IntPtr(PRF_CLIENT | PRF_CHILDREN);
				Message msg = Message.Create(this.Handle, WM_PRINT, wParam, lParam);
				this.WndProc(ref msg);
			}
			catch { }
			finally
			{
				if (gr != null)
				{
					if (hdc != IntPtr.Zero)
						gr.ReleaseHdc(hdc);
					gr.Dispose();
				}
			}
			return bmp;
		}
 
		private void Imprimer_Click(object sender, System.EventArgs e)
		{
			Imprimer.Visible = false;
 
			PrintDocument pd = new PrintDocument();
 
			// évènement déclenché juste avant l'impression pour obtenir un dessin
			pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); 
 
			// lancement de l'impression
			pd.Print(); 
		}
 
		private void pd_PrintPage(object sender, PrintPageEventArgs e) 
		{ 
			// Là c'est comme si tu fais un dessin normal 
			Graphics dc = e.Graphics; 
 
			e.Graphics.DrawImage(PrintWindowEx(), new PointF(50, 10));
 
			// Test s'il n'y a plus aucune page à imprimer 
			if ( dc == null ) 
				e.HasMorePages = true;
			else 
				e.HasMorePages = false;  
		}
Comment je peux faire pour mette les données du dataGrid1 de la première form dans un autre dataGrid dans la form2??

Cordialement.